Repository navigation
[PHP-WASM] Transfer event stdin streams across workers - #4060
Merged
Merged
Conversation
adamziel
requested review from
a team,
JanJakes and
Copilot
and removed request for
Copilot
July 15, 2026 09:31
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for transferring ReadableStream instances nested inside worker-dispatched events (e.g., stdin on a PHPWorker event) across the Comlink boundary, including a Safari fallback via MessagePort, and validates the behavior with a Playwright test.
Changes:
- Register Comlink transfer handlers for
ReadableStream<Uint8Array>and for event objects that contain nested streams. - Update
PHPWorker.dispatchEvent()to teestdinstreams so each listener receives a transferable branch. - Add a Playwright worker + spec to verify multi-listener delivery and that the source stream remains live during reads.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/php-wasm/web/src/test/readable-stream-transfer.spec.ts | New Playwright spec validating cross-worker stream transfer to multiple listeners. |
| packages/php-wasm/web/src/test/playwright/readable-stream-worker.ts | New worker script that emits an event containing a ReadableStream payload. |
| packages/php-wasm/web/src/test/playwright/browser-globals.ts | Exposes worker-spawn + API-consumption helpers and the worker URL to the browser test page. |
| packages/php-wasm/web/playwright.config.ts | Includes the new stream-transfer spec in the Playwright run. |
| packages/php-wasm/universal/src/lib/php-worker.ts | Tees readable stdin streams per listener to avoid one-time transfer limitations. |
| packages/php-wasm/universal/src/lib/api.ts | Adds Comlink transfer handlers for ReadableStream and nested-stream event payloads (Safari fallback via MessagePort). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PHPWorkercan now deliver an event whosestdinremains a liveReadableStreamacross the browser worker boundary. Comlink applies transfer handlers only to the top-level value, so a stream stored in an event'sstdinproperty otherwise reachespostMessage()without a transfer list and structured cloning fails.The event handler serializes
stdinthrough a dedicated stream handler. It transfers the stream directly when the runtime supports that operation and uses the existingMessagePortbridge otherwise. The bridge transfers owned chunk copies becauseReadableStream.tee()branches share chunk objects and detaching one branch's buffer must not invalidate the others. Consumer cancellation travels back over the port and cancels the source reader.A stream can only be transferred once, so
PHPWorkergives each listener its own tee branch. Slow listeners may queue unread chunks because this transport does not coordinate backpressure between branches.Browser-worker tests cover native stream transfer and the forced
MessagePortfallback, including incremental delivery to two listeners and source cancellation after both tee branches cancel.This is the worker transport required by #3996. It adds no sendmail behavior.