-
Notifications
You must be signed in to change notification settings - Fork 295
Support proc_open(), exec(), passthru(), system() #596
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
Conversation
this seems quite usable, though maybe we need to figure out how to make the difference between browser and Node environments less implicit. if running in Node certain things will work that crash in the browser. I wonder if we can stub the functions in the web version to do something benign. obviously we can't spawn arbitrary processes because we only have PHP and SQLite built. what is PHP spawning? is this only important when running the WordPress test suites? |
68f2a1d
to
9e375d2
Compare
Good call! I added this: if (!ENVIRONMENT_IS_NODE) {
return 1; // proc_open() is not supported in the browser yet.
}
Mostly it's spawning Spawning another WebAssembly PHP instance could just work on the web. We could even open up wider |
1036db3
to
d60493f
Compare
f658e8b
to
b4cfb8c
Compare
Provides a custom implementation of: * php_exec – under the name wasm_php_exec * proc_open Both allow the C API to call a JavaScript callback set via setSpawnHandler().
f8d37d2
to
20692e3
Compare
Continues the work from #710 and #596. Rewires the PHP `VCWD_POPEN` macro used internally to spawn a new process to Playground-provided implementation called `wasm_popen`. This enables handling the `shell_exec` calls using the same `createSpawnHandler()` JavaScript callback as all the other process-opening functions like `proc_open`, `system`, or `exec` ## Testing instructions This PR ships a unit test for `shell_exec()` so you just need to confirm that test passes.
Description
Adds support for proc_open(), popen($cmd, "w"), exec(), passthru(), system() 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 newproc_open7.0.c
/proc_open7.4.c
file. The originalproc_open()
relies on POSIXfork()
function not available in WebAssembly, so which is why this PR defers the command execution to thesetSpawnHandler()
callback provided via JavaScript.exec()
,passthru()
,system()
This PR provides a custom
php_exec
implementation (via thewasm_php_exec
C function).php_exec
is the function powering PHP functions likeexec()
,passthru()
,system()
.popen()
The existing
popen()
implementation is rewired to call thesetSpawnHandler()
callback. Also, the support for thepopen($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