-
Notifications
You must be signed in to change notification settings - Fork 315
[PHP] Support non-blocking read streams #2339
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… syscalls instead.
It seems like we could just remove our |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[Feature] PHP.wasm
[Package][@php-wasm] Node
[Package][@php-wasm] Web
[Type] Enhancement
New feature or request
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds supports for reading from non-blocking streams
(
stream_set_blocking($fp, true)
) by aligning the streaming logic withunix kernel:
stream_set_blocking()
is now able to correctly mark the OS stream asnon blocking via
fcntl()
fd_read()
either blocks or immediately returns based on stream typejs_open_process()
,proc_open()
et al. now work directly withkernel pipes. There's no more special event-based handling, polling, or
special casing for pumping stdin data to the process.
data, and the other side is already closed
PHPWASM.child_proc_by_fd
. We rely on kernel pipes now.Motivation for this patch
With this PR, we can use the Symfony Process component. It spawns a new
process via proc_open(), marks its output stream as non-blocking, and
immediately reads the initial output bytes if any are present. Before
this change, Playground would block until the first output is produced,
and, sometimes until the entire process finishes.
This PR is a pre-requisite to #2281
Other changes
This PR implements
usleep()
(via-Wl,--wrap=usleep
). It turns outthat it wasn't actually blocking the execution and a few unit tests
relying on it only passed due to a buggy implementation of blocking
streams.
Follow-up work
read()
globally with something equivalent towasm_read()
.Right now we only do this
RUN /root/replace.sh 's/ret = read/ret = wasm_read/g' /root/php-src/main/streams/plain_wrapper.c
php_pollfd_for
and removingwasm_poll_socket()
– wrapping select/poll/read syscalls may be enoughwasm_poll_socket
, thejs_popen_to_file
function,awaitData
et al.Testing Instructions (or ideally a Blueprint)
Tests are included so just confirm the CI is green.