Skip to content

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Sep 26, 2025

Motivation for the change, related issues

Makes playground.cli() and playground.runStream() available for Playground integrators.

Without this PR, these methods can only be called from the same JavaScript process where the PHP is running. If you try to call it over Comlink, you get an error TypeError: Unserializable return value as Comlink doesn't know how to transfer a StreamedPHPResponse object over to another worker..

With this PR, you can call both these methods on a PHP Client and Comlink will correctly transfer the StreamedPHPResponse object.

This unlocks exposing a XTerm.js widget with WP-CLI and Composer commands.

Implementation details

Implements a new transfer handle that uses a few lengthy utility methods to convert between promises and streams and MessagePort instances. On most browsers, it uses the transferable property of a ReadableStream. On Safari, it falls back to MessagePorts.

Testing Instructions (or ideally a Blueprint)

CI – this PR ships a new E2E test.

Also, try this in devtools:

await playground.writeFile('/tmp/script.php', "<?php echo 'hi!'; ");
const r = await playground.cli(['php', '/tmp/script.php']);
await r.stdoutText

You should se "hi!".

cc @mho22 @brandonpayton

@adamziel adamziel merged commit 2c3b9bf into trunk Sep 26, 2025
26 of 27 checks passed
@adamziel adamziel deleted the transfer-streaming-response branch September 26, 2025 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant