Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f34feb0
Revert "[ php-wasm ] Reject browser clients in the outbound networkin…
brandonpayton Nov 5, 2026
acdb9a4
[ php-wasm ] Open outbound TCP connections without a local server
brandonpayton Nov 5, 2026
1052308
[ php-wasm ] Keep outboundNetworkProxyServer as a deprecated option
brandonpayton Nov 5, 2026
4bc6dcf
[ php-wasm ] Name the return type of createOutboundTcpSocketClass
brandonpayton Nov 5, 2026
0f0f513
[ php-wasm ] Open outbound sockets before the TCP connection completes
brandonpayton Nov 5, 2026
6cabf32
[ php-wasm ] Accept inbound TCP connections without a WebSocket bridge
brandonpayton Nov 5, 2026
45eef64
[ php-wasm ] Rename the socket spec to match tcp-socket.ts
brandonpayton Nov 5, 2026
496f41f
[ php-wasm ] Release TCP sockets when the runtime exits
brandonpayton Nov 5, 2026
0efe03f
[ php-wasm ] Stop on listen errors and listen on IPv4 for hostnames
brandonpayton Nov 6, 2026
e5e7509
[ php-wasm ] Don't listen after a server closes during its hostname l…
brandonpayton Nov 6, 2026
8420138
[ php-wasm ] Run the networking tests with Asyncify in CI
brandonpayton Nov 6, 2026
a2a1bf7
[ php-wasm ] Test networking in the built npm packages
brandonpayton Nov 6, 2026
f1aaf8b
[ php-wasm ] Refuse to run the Asyncify networking tests with JSPI
brandonpayton Nov 6, 2026
7bdeba1
[ php-wasm ] Drop data after PHP closes a TCP socket
brandonpayton Nov 6, 2026
8dbdf76
[ php-wasm ] Avoid an Asyncify accept() crash in the inbound test
brandonpayton Nov 6, 2026
6ea6cf8
[ php-wasm ] Fix reset handling in the TCP socket adapters
brandonpayton Nov 7, 2026
05f42cd
[ php-wasm ] Make the runtime exit test check exit cleanup directly
brandonpayton Nov 7, 2026
264dabb
[ php-wasm ] Explain the less obvious choices in the TCP adapters
brandonpayton Nov 7, 2026
22bb66c
[ php-wasm ] Test the missing-address check deterministically
brandonpayton Nov 7, 2026
37322d0
[ php-wasm ] Drop data after close without resetting the connection
brandonpayton Nov 7, 2026
4c3e36e
[ php-wasm ] Keep sending a closed socket's writes when the runtime e…
brandonpayton Nov 7, 2026
34bfb90
[ php-wasm ] Tighten exit cleanup tests and comments
brandonpayton Nov 7, 2026
1d7043e
[ php-wasm ] Release every network handle even if one fails
brandonpayton Nov 7, 2026
8f697e7
[ php-wasm ] Stop the timeout test from breaking setTimeout for later…
brandonpayton Nov 7, 2026
0167dda
[ php-wasm ] Keep a closeNetworkConnections option passed to withNetw…
brandonpayton Nov 7, 2026
b748716
[ php-wasm ] Drain TCP writes and release cleanup timers on exit
brandonpayton Nov 7, 2026
d73cccc
[ php-wasm ] Test that exit unrefs every socket, and explain tradeoffs
brandonpayton Nov 7, 2026
c57cf61
[ php-wasm ] State what a released socket retains, and for how long
brandonpayton Nov 8, 2026
20d233b
[ php-wasm ] Say when stream_select() reports a listening socket ready
brandonpayton Nov 8, 2026
b236bec
[ php-wasm ] Wait for PHP's connections before testing exit unrefs them
brandonpayton Nov 8, 2026
60d31f5
[ php-wasm ] Don't wake PHP when the runtime exits
brandonpayton Nov 8, 2026
f64d33a
[ php-wasm ] Cancel network waits before releasing exited runtimes
brandonpayton Nov 9, 2026
eeb449b
[ php-wasm ] Keep exit handling in the Node TCP adapters
brandonpayton Nov 9, 2026
0995bd5
[ php-wasm ] Make the exit guard tests fail without the guard
brandonpayton Nov 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,50 @@ jobs:
MYSQL_DATABASE: test_db
MYSQL_USER: user
MYSQL_PASSWORD: password
# Node.js enables JSPI by default from 24.20.0, so the test-unit-asyncify
# jobs above load the JSPI build too. Node 24.18.0, the oldest supported
# version, still loads the Asyncify build. Run the networking tests there.
test-networking-asyncify:
needs: set-nx-shas
if: github.repository == 'WordPress/wordpress-playground' || github.event_name == 'pull_request'
name: 'Networking tests with Asyncify (Node 24.18.0)'
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read # Required to clone the repo.
env:
NX_BASE: ${{ needs.set-nx-shas.outputs.base }}
NX_HEAD: ${{ needs.set-nx-shas.outputs.head }}
services:
mysql:
image: mysql:5.7
env:
MYSQL_DATABASE: test_db
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: rootpassword
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- uses: actions/checkout@v4
with:
submodules: true
# Install with Node 24 to reuse the shared dependency cache, then
# switch to the version that loads the Asyncify build.
- uses: ./.github/actions/prepare-playground
- uses: actions/setup-node@v4
with:
node-version: 24.18.0
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-networking-asyncify
env:
MYSQL_DATABASE: test_db
MYSQL_USER: user
MYSQL_PASSWORD: password
test-playground-cli:
needs: set-nx-shas
if: github.repository == 'WordPress/wordpress-playground' || github.event_name == 'pull_request'
Expand Down
5 changes: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ and runs PHP/SQLite, CLI multi-worker, and worker-wait tests with that addon mov
out of resolution.
The addon is restored before the shared dependency cache is saved.

Node.js enables JSPI by default from 24.20.0, so the `-asyncify` unit test targets
load the JSPI build in CI. The `test-networking-asyncify` job runs the
`@php-wasm/node` networking tests on Node 24.18.0, which loads the Asyncify build.
Its `vite.asyncify.config.ts` stops with an error on Node versions that enable JSPI.

Dependabot's daily version check opens PRs for `fs-ext-extra-prebuilt` patch
releases. It raises the minimum package version and updates the lockfile; the
existing Dependabot lockfile workflow preserves workspace links. An explicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Consult the [complete list](/api/node) of Classes, Functions, Interfaces, and Ty
Together, `@php-wasm/node` and a version-specific package provide the compiled
PHP runtime and JavaScript API optimized for Node.js. PHP starts with an
in-memory filesystem; use the Node.js filesystem helpers to mount host paths.
The runtime can access the network if you plug in a custom WebSocket-to-TCP
proxy.
PHP can open TCP connections and listen for them. The runtime uses Node.js
TCP sockets directly.

### Basic usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Because every PHP version is just a static .wasm file, the PHP version switcher

When it comes to networking, WebAssembly programs are limited to calling JavaScript APIs. It is a safety feature, but also presents a challenge. How do you support low-level, synchronous networking code used by PHP with the high-level asynchronous APIs available in JavaScript?

In Node.js, the answer involves a WebSocket to TCP socket proxy, [Asyncify](https://emscripten.org/docs/porting/asyncify.html), and patching deep PHP internals like php_select. It's complex, but there's a reward. The Node.js-targeted PHP build can request web APIs, install composer packages, and even connect to a MySQL server.
In Node.js, the answer involves TCP sockets that stand in for Emscripten's WebSockets, [Asyncify](https://emscripten.org/docs/porting/asyncify.html), and patching deep PHP internals like php_select. It's complex, but there's a reward. The Node.js-targeted PHP build can request web APIs, install composer packages, and even connect to a MySQL server.

In the browser, networking is supported in two ways:

Expand Down
11 changes: 9 additions & 2 deletions packages/php-wasm/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ This package ships WebAssembly PHP binaries and the JavaScript API optimized for
- OpenSSL
- MySQL

It uses the host filesystem directly and can access the network if you plug in a custom
WS proxy.
It uses the host filesystem and TCP sockets directly.

Here's how to use it:

Expand All @@ -27,6 +26,14 @@ const output = await php.runStream({
console.log(await output.stdoutText);
```

On runtime exit, listening sockets close and TCP sockets have up to 30 seconds
to drain queued writes. The exited runtime cannot open new network connections.
As on previous runtimes, `php.exit()` does not provide general cancellation of
PHP code that was already executing. PHP waiting on a socket when the runtime
exits may resume and finish its script, including writes to mounted files, but
it can't open network connections. A `stream_socket_server()` call after exit
fails the request.

## Loading PHP extensions

Pass `extensions` to `loadNodeRuntime()` to load optional PHP extensions before
Expand Down
23 changes: 21 additions & 2 deletions packages/php-wasm/node/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
"php-sqlite3.spec.ts",
"php-networking.spec.ts",
"networking-port-allocation.spec.ts",
"outbound-ws-to-tcp-proxy.spec.ts",
"tcp-socket.spec.ts",
"php-dynamic-loading.spec.ts",
"php-mysqli.spec.ts",
"php-process-manager.spec.ts",
Expand All @@ -252,7 +252,7 @@
"php-sqlite3.spec.ts",
"php-networking.spec.ts",
"networking-port-allocation.spec.ts",
"outbound-ws-to-tcp-proxy.spec.ts",
"tcp-socket.spec.ts",
"php-dynamic-loading.spec.ts",
"php-mysqli.spec.ts",
"php-process-manager.spec.ts",
Expand Down Expand Up @@ -312,6 +312,25 @@
"testFiles": ["php-part-2.spec.ts"]
}
},
"test-networking-asyncify": {
"executor": "@nx/vitest:test",
"outputs": ["{workspaceRoot}/coverage/packages/php-wasm/node"],
"options": {
"configFile": "packages/php-wasm/node/vite.asyncify.config.ts",
"reportsDirectory": "../../../coverage/packages/php-wasm/node",
"testFiles": [
"tcp-socket.spec.ts",
"networking-port-allocation.spec.ts",
"php-networking.spec.ts",
"php-fsockopen.spec.ts",
"php-socket-timeouts.spec.ts",
"php-file-get-contents.spec.ts",
"php-fopen.spec.ts",
"php-gethostbyname.spec.ts",
"php-mysqli.spec.ts"
]
}
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
"test-redis-extension-jspi": {
"executor": "@nx/vitest:test",
"outputs": ["{workspaceRoot}/coverage/packages/php-wasm/node"],
Expand Down
117 changes: 0 additions & 117 deletions packages/php-wasm/node/src/lib/networking/inbound-tcp-to-ws-proxy.ts

This file was deleted.

Loading
Loading