-
Notifications
You must be signed in to change notification settings - Fork 295
Prototype: Spawning PHP sub-processes in Web Workers #1031
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
while normal environments share the FS across running PHP instances, I wonder if there would be a special reason to lock the FS during Playground bootup, in case something depends on having certain plugins installed or wants to read config values. I'm thinking about the case where a worker and main thread are both initializing at the same time. did you work through these cases? |
Introduces a naive shell command parser to provide equally good support for the following two types of `proc_open()` calls: ```php proc_open([ "wp-cli.phar", "plugin", "install", "gutenberg" ]); proc_open("wp-cli.phar plugin install gutenberg" ]); ``` The command parsing semantics are extremely naive at this point and only cover splitting the command into an array of arguments as follows: ```ts splitShellCommand(`wp option set blogname "My \"fancy\" blog "'name'`); > ["wp", "option", "set", "blogname", `my "fancy" blog name`] ``` There is no support for inline ENV variables, pipes, or redirects. For those, we might need to build an actual shell binary OR turn to something like [bun shell](#1062). ## Testing instructions This PR ships unit tests so just confirm the CI checks pass. ## Related resources * #1031 * #1062 * #1051
Both PHP instances run in the same worker so there is no concurrency involved. Everything is happening sequentially. Assuming reliable two-way Filesystem sync, both PHP instances would have access to the same plugins and config values. |
Perhaps we don't need to sync filesystem changes after all. Emscripten provides PROXYFS that could potentially enable mounting one of the filesystems in the other, effectively making both PHP instances work with the same files. |
childPHP = new WebPHP(await recreateRuntime(), { | ||
documentRoot: DOCROOT, | ||
absoluteUrl: scopedSiteUrl, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an alternative idea for FS syncing:
for ( const path of [DOCROOT, "/tmp"] ) {
childPHP[__private__dont__use].FS.mount(childPHP[__private__dont__use].PROXYFS, {
root: path,
fs: php[__private__dont__use].FS
}, path);
}
Superseded by #1069 |
Related to #1026 and #1027
Adds support for spawning PHP subprocesses via
<?php proc_open(['php', 'activate_theme.php']);
. The spawned subprocess affects the filesystem used by the parent process.Implementation details
This PR adds a
spawnHandler
that does the following:A shared filesystem didn't pan out. Synchronizing is the second best option.
This code snippet illustrates the idea – note the actual implementation is more nuanced:
Future work
stdout
andstderr
fromchildPHP
toprocessApi
instead of buffering the output and passing everything at onceExample of how it works
/wordpress/spawn.php
/wordpress/child.php
Testing instructions
Unit tests, E2E tests, and more testing instructions coming soon.
cc @dmsnell @bgrgicak