-
Notifications
You must be signed in to change notification settings - Fork 358
PHP: Stream stdout and stderr #2261
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
15bf8ed to
53e5126
Compare
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 found the original PR and it looks like I just replaced all console.error calls with logger.error, so this might be a good time to rethink if we really need these log entries.
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.
Aha, good spot! Thank you
f3bca7e to
4c5aa92
Compare
1271db7 to
5cfa0e9
Compare
7f310d7 to
58956fc
Compare
Implements a php.runStream() method that returns a StreamedPHPResponse instance. It exposes stdout and stderr as ReadableStreams, allowing the caller to interact with partial output data. Before this PR, we only had php.run() that buffered stdout and stderr data and returned it all at once after the PHP code was fully executed. ## Implementation We register three FS devices at: * /internal/stdout * /internal/stderr * /internal/headers They are private to every PHP instance and are never shared with other runtimes. Then, in JavaScript, whenever a chunk of data is written to either of these devices, we propagate it to consumer via a callback, e.g. `PHPWASM.onStdout(chunk)`. Users of the `PHP` class never have to interact with these devices or callbacks directly. The PHP class creates the relevant ReadableStreams and pushes the data through them – see php.#executeWithErrorHandling() for details. #### Why not use Emscripten's stdout and stderr? Emscripten's native stdout and stderr devices stop processing data when they encounter the first null byte. However, null bytes are common when dealing with binary data. ### Backwards Compatibility php.run() continues to work. It creates a streamed response under the hood and buffers the streamed output before returning a buffered `PHPResponse` object. ## Remaining work * Add streaming-specific tests ## Follow-up work * Stream the response bytes in the web/service worker Remove old PHP CLI bindings
58956fc to
e64002f
Compare
Implements a php.runStream() method that returns a StreamedPHPResponse instance.
It exposes stdout and stderr as ReadableStreams, allowing the caller to interact
with partial output data. Before this PR, we only had php.run() that buffered
stdout and stderr data and returned it all at once after the PHP code was fully
executed.
Implementation
We register three FS devices at:
They are private to every PHP instance and are never shared with other runtimes.
Then, in JavaScript, whenever a chunk of data is written to either of these devices, we propagate
it to consumer via a callback, e.g.
PHPWASM.onStdout(chunk).Users of the
PHPclass never have to interact with these devices or callbacks directly.The PHP class creates the relevant ReadableStreams and pushes the data through them
– see php.#executeWithErrorHandling() for details.
Why not use Emscripten's stdout and stderr?
Emscripten's native stdout and stderr devices stop processing data when they encounter
the first null byte. However, null bytes are common when dealing with binary data.
Backwards Compatibility
php.run() continues to work. It creates a streamed response under the hood and buffers
the streamed output before returning a buffered
PHPResponseobject.Remaining work
Follow-up work