Repository navigation
Description
PHPUnit and wp-cli both use proc_open and will only work correctly in WordPress Playground if that function is supported.
Today proc_open does not work becuse internally it calls fork() which is not supported in Emscripten and doesn't seem possible to polyfill.
Therefore, the only way to support proc_open is to shim it using require('child_process').spawn() similarly to how we shim popen():
wordpress-playground/packages/php-wasm/compile/build-assets/phpwasm-emscripten-library.js
Line 346 in cd4062d
| js_popen_to_file: function(command, mode, exitCodePtr) { |
wordpress-playground/packages/php-wasm/compile/build-assets/phpwasm-emscripten-library.js
Lines 372 to 384 in cd4062d
| const cp = require('child_process'); | |
| let ret; | |
| if (modestr === 'r') { | |
| ret = cp.spawnSync(cmdstr, [], { | |
| shell: true, | |
| stdio: ["inherit", "pipe", "inherit"], | |
| }); | |
| HEAPU8[exitCodePtr] = ret.status; | |
| require('fs').writeFileSync(pipeFilePath, ret.stdout, { | |
| encoding: 'utf8', | |
| flag: 'w+', | |
| }); | |
| } else if (modestr === 'w') { |
proc_open has the following signature in PHP:
proc_open(
array|string $command,
array $descriptor_spec,
array &$pipes,
?string $cwd = null,
?array $env_vars = null,
?array $options = null
): resource|falseHandling $pipes is the most challenging bit here. Emscripten documentation doesn't explain how to create pipes – the easiest way should be reading the code and looking up examples.
If we can find a way to open Emscripten pipes and pass the data from/to the child process, that's great – that would probably involve custom Emscripten streams or devices. Otherwise, we could fake pipes by opening three temporary files in Emscripten (for stdin, stdout, stderr) and creating $pipes using those file descriptor.
Activity
adamziel commentedon Jun 25, 2023
PHPUnit uses
proc_opento support process isolation (which WordPress relies on):TestCase::run():
TestRunner::runInSeparateProcess:
DefaultPhpProcess::runProcess():
[-]Support proc_open[/-][+]PHP: Support proc_open[/+]adamziel commentedon Jun 25, 2023
wp-cli proc_open usages
Support proc_open(), exec(), passthru(), system() (#596)