-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHP: Support proc_open #594
Labels
Comments
PHPUnit uses if (!$this->shouldRunInSeparateProcess()) {
(new TestRunner)->run($this);
} else {
(new TestRunner)->runInSeparateProcess(
$this,
$this->runClassInSeparateProcess && !$this->runTestInSeparateProcess,
$this->preserveGlobalState,
);
}
} TestRunner::runInSeparateProcess: $php = AbstractPhpProcess::factory();
$php->runTestJob($template->render(), $test); DefaultPhpProcess::runProcess(): $process = proc_open(
$this->getCommand($settings, $this->tempFile),
$pipeSpec,
$pipes,
null,
$env,
); |
This was referenced Jun 25, 2023
adamziel
added a commit
that referenced
this issue
Oct 24, 2023
## Description Adds [support for proc_open(), popen($cmd, "w"), exec(), passthru(), system()](b4cfb8c) via a custom spawn handler defined in JavaScript via `php.setSpawnHandler()`. ### `proc_open()` This PR patches PHP to replace C calls to `proc_open()` with a custom implementation provided with a new `proc_open7.0.c`/`proc_open7.4.c` file. The original `proc_open()` relies on POSIX `fork()` function not available in WebAssembly, so which is why this PR defers the command execution to the `setSpawnHandler()` callback provided via JavaScript. ### `exec()`, `passthru()`, `system()` This PR provides a custom `php_exec` implementation (via the `wasm_php_exec` C function). `php_exec` is the function powering PHP functions like `exec()`, `passthru()`, `system()`. ### `popen()` The existing `popen()` implementation is rewired to call the `setSpawnHandler()` callback. Also, the support for the `popen($cmd, "w")` mode was added. ### Other notes This PR removes support for PHP 5.6 as supporting these functions was challenging there AND also WordPress dropped the support for PHP 5.6. Closes #594 Closes #710
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 callsfork()
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 usingrequire('child_process').spawn()
similarly to how we shimpopen()
:wordpress-playground/packages/php-wasm/compile/build-assets/phpwasm-emscripten-library.js
Line 346 in cd4062d
wordpress-playground/packages/php-wasm/compile/build-assets/phpwasm-emscripten-library.js
Lines 372 to 384 in cd4062d
proc_open
has the following signature in PHP:Handling
$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.cc @wojtekn @sejas @danielbachhuber @schlessera
The text was updated successfully, but these errors were encountered: