-
Notifications
You must be signed in to change notification settings - Fork 276
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
Spawning PHP sub-processes in Web Workers #1069
Conversation
## What is this PR doing? Supersedes #1051 Adds a PHP Blueprints demo page where the use of [blueprints.phar](WordPress/blueprints#28) PHP library in Playground may be further explored. The showcase is intentionally not added to http://localhost:5400/website-server/demos/index.html as PHP Blueprints may become a part of Playground core soon enough. For more context see: * #1025 * https://github.com/WordPress/blueprints ## How does it work? * The built Blueprints library is included with this PR via the `blueprints.phar` file * A number of PHP.wasm improvements have been merged to support it: * #1064 * #1065 * #1069 * This PR ships a `fetch` subprocess handler to enable streaming network data in the Blueprints library – it uses [a special network transport called `fetch`](https://github.com/WordPress/blueprints/blob/efa8deef56095bd5bcb94868787e29f7b54350f3/src/WordPress/DataSource/PlaygroundFetchSource.php) that requests network data via `proc_open()` when running in Playground. Why subprocesses? They provide everything a custom network handler needs: pipes, asynchronous execution, exit codes, internal PHP plumbing. ## Follow-up work * Support a real-time progress bar ## Testing instructions Go to http://localhost:5400/website-server/demos/php-blueprints.html and confirm it looks like on the screenshot below: 
if (!childPHP.fileExists(path)) { | ||
childPHP.mkdir(path); | ||
} | ||
childPHP[__private__dont__use].FS.mount( | ||
childPHP[__private__dont__use].PROXYFS, | ||
{ | ||
root: path, | ||
fs: php[__private__dont__use].FS, | ||
}, | ||
path | ||
); | ||
} |
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.
Nice! Glad you found a way without copying the files.
define('STDIN', fopen('php://stdin', 'rb')); | ||
define('STDOUT', fopen('php://stdout', 'wb')); | ||
define('STDERR', fopen('/tmp/stderr', 'wb')); | ||
|
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.
Should this be /internal/stderr
?
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.
Oh! Yeah if that remains a file path then yes. I wonder why this isn't php://stderr
actually, I think I copied it over from #161 and, at that time, there was a bug preventing the use of php://stderr
.
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.
I created an issue to track it here: #1071
…ead of /tmp/stderr (#173) Adapts the block to the changes implemented in WordPress/wordpress-playground#1069
Related to #1026, #1027, and #1051. Supersedes #1031
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 updates the default
spawnHandler
inworker-thread.ts
that creates another WebPHP instance and mounts the parent filesystem using Emscripten's PROXYFS.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
worker-thread.ts
to create the two files listed above/spawn.php
cc @dmsnell @bgrgicak