-
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 read() from a blocking pipe #931
Conversation
…ding proc_open() output
Relevant explorations: #951 (comment) |
Shims read(2) functionallity by providing an alternative read() function called wasm_read() that gracefully handles blocking pipes. This is neecessary because Emscripten does not support blocking pipes and instead returns EWOULDBLOCK. See: * #951 * emscripten-core/emscripten#13214 ## Testing instructions Confirm the `proc_open()` tests pass on CI. This PR adjusts a few of them to make sure the output is read without the tricky sleep() call.
…pty file starts polling.
|
||
if (returnCode === 6 /*EWOULDBLOCK*/) { | ||
return Asyncify.handleSleep(function (wakeUp) { | ||
var timeout = 10000; // @TODO Do not hardcode this |
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.
😄
what actually happens if we do timeout letting this run indefinitely? will the PHP process run its own timeout? if that's the case, is it safe to let this block forever?
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. Yes, I think we're good to just let this block until PHP times out.
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.
Actually, this may block a PHPUnit test suite without any visible feedback so I think we have to give up eventually. It's a shame, I'd rather rely on PHP timeout.
One remaining issue is reading from a blocking file pipe as opposed to just a process pipe. |
Shims read(2) functionallity by providing an alternative read()
function called wasm_read() that gracefully handles blocking
pipes. This is neecessary because Emscripten returns EWOULDBLOCK
when reading from a blocking pipe, whereas a clang-compiled
program would wait until data becomes available.
See:
Other changes
This PR also ships:
@php-wasm/cli
to preserve a trailing whitespace when rewrite PHP-related spawn shell commands.Motivation
wp-cli
Without this PR, running
wp-cli.phar
doesn't output anything. The output is piped through a pager likeless
usingproc_open
and then displayed by reading from a blocking pipe.With this PR, running
wp-cli.phar
returns its regular help message as the pager pipe can be read:PHPUnit
With this PR, Playground can run PHPunit on
wordpress-develop
!Testing instructions
Confirm the
proc_open()
tests pass on CI. This PR adjusts a fewof them to make sure the output is read without the tricky sleep()
call.
Related:
CC @mho22