[CLI] Add a native Wasmtime Playground CLI with PHP 7.4–8.5 and extensions - #3837
Draft
adamziel wants to merge 31 commits into
Draft
[CLI] Add a native Wasmtime Playground CLI with PHP 7.4–8.5 and extensions#3837adamziel wants to merge 31 commits into
adamziel wants to merge 31 commits into
Conversation
adamziel
force-pushed
the
recovered-wasmtime-playground-cli
branch
from
July 3, 2026 15:07
2ce9526 to
8ca5193
Compare
adamziel
force-pushed
the
recovered-wasmtime-playground-cli
branch
3 times, most recently
from
July 5, 2026 17:11
bad74d7 to
bf49548
Compare
adamziel
force-pushed
the
recovered-wasmtime-playground-cli
branch
from
July 12, 2026 01:14
a5912f2 to
f7a7daa
Compare
adamziel
force-pushed
the
recovered-wasmtime-playground-cli
branch
6 times, most recently
from
July 12, 2026 14:51
ae0f4c9 to
f22ecf5
Compare
adamziel
force-pushed
the
recovered-wasmtime-playground-cli
branch
from
July 13, 2026 15:21
f22ecf5 to
9445759
Compare
Encode zero-valued filesystem timestamps without treating them as missing so packaged WordPress scripts remain cacheable while mounted edits still revalidate. Return the first Wasmtime-owned PHP output buffer directly instead of copying it.
Mirror each component's private wal-index through a process-local canonical host image using typed open, reset, epoch, and atomic exchange operations. Synchronize at SQLite lock and barrier boundaries, including exclusive-mode transitions and close/reopen recovery, while retaining per-file lock sharding and bounded delta history.
adamziel
force-pushed
the
recovered-wasmtime-playground-cli
branch
from
July 16, 2026 19:01
7e206b0 to
f64f392
Compare
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.
What it does
Adds a Node-free WordPress Playground runtime backed by persistent PHP WASI Preview 2 components and Wasmtime. It supports
start,server,run-blueprint, andbuild-snapshot, including WordPress installation, mounts, snapshots, real PHP CLI/WP-CLI execution, configurable parallel workers, SQLite range locks, and process-local WAL coordination.Adds an unpublished-to-npm
@wp-playground/cli-nativepackage as a drop-in experiment for the declared@wp-playground/clisurface. The private package provides ESM, CommonJS, declarations,wp-playground-cli, structured one-shot/server results, an async-disposable server, and a protocol-v2 Playground proxy.The runtime now ships base and extended WASIp2 components for PHP 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, and 8.5. Extended components contain Redis 6.3.0, Memcached 3.4.0, and the PHP-series-compatible Xdebug release. The base component remains the default; Redis and Memcached follow the Node CLI's JSPI default at the npm boundary, and explicit flags select either profile.
This PR remains a draft and does not publish to npm or add a stable release path, embedded native executable,
.cwasm, or default production download URL. The package staysprivate, and host acquisition requires an explicitWP_PLAYGROUND_NATIVE_HOST_BASE_URL. A one-off GitHub prerelease is available solely for macOS testing.Rationale
The original core-Wasm prototype reproduced a large PHP host environment in Rust. At the giant-host baseline,
host.rsplusphp.rsoccupied 23,041 physical lines. The current PHP/WASIp2 host, component bridge, and authored WIT total 10,629 lines, a 54% reduction while also adding real PHP CLI, WAL, cancellation, PHP 7.4–8.5, and extensions. The complete Rustsrc/tree is 41,845 lines versus 52,795 at that baseline.The portable unit is the PHP component, not the Wasmtime host. Wasmtime depends on native JIT, virtual memory, and OS handles, so the npm shell carries raw component Wasm and acquires the correct verified native host on first use.
runtime installcan prewarm Wasmtime's platform cache; no source build or Wasm-to-native conversion is required at ordinary startup.SQLite normally shares its wal-index through
xShm*memory. Independent component workers cannot share guest memory, while rollback-journal mode serializes mixed and admin traffic. The native host therefore keeps a sharded canonical wal-index and exchanges typed deltas with each worker at SQLite lock and barrier boundaries.Implementation
Storeand persistent PHP instance around one shared compiled component. Explicit pools stay warm; automatically sized excess workers retire after 10 seconds; workers recycle after 3,000 requests by default.playground.cli(argv, { env, cwd })reserves pool capacity, starts a fresh interruptible component, streams stdout/stderr, returns PHP's exit code, and runs the bundled WP-CLI Phar.zend_list_free()through an exact void-returning resource-destructor callback, avoiding a typed WebAssemblycall_indirecttrap during resource release.open,reset,current-epoch, and atomicexchangeoperations. Coordination is process-local; separate native CLI processes must not concurrently open the same mounted WAL database.runCLI,parseOptionsAndRunCLI, server, event, filesystem, andUniversalPHPsurfaces.studio wp, restart persistence, Blueprints, Xdebug, and JSPI-gated Redis/Memcached..cwasm, Cargo output, or stable release workflow enters the private tarball.Experimental macOS prerelease
Download the one-off macOS prerelease. It targets exact source commit
9a437319d6c5ac47d92cb8f0f265e6ed1b36914b, is marked prerelease and non-latest, and contains one private npm tarball plus separate Intel and Apple Silicon gzip hosts, a combined manifest, provenance, and checksums. It is not published to npm.The PR-scoped build workflow has read-only repository permission. It built and verified each architecture independently, assembled flat GitHub asset paths, and then installed the exact final tarball on fresh macOS x64 and ARM64 runners. Both final runners acquired their hashed host and passed PHP 8.2 HTTP and CLI execution before the inspected bytes were published.
Testing instructions
Run the repository and installed-package gates:
Run the real PHP/extension matrix with Redis and Memcached on
PATH:nix --extra-experimental-features 'nix-command flakes' \ shell nixpkgs#redis nixpkgs#memcached -c \ packages/playground/cli-native/scripts/verify-php-runtime-matrix.shThe final local repository gate passed 133 npm tests, 371 Rust library tests, 20 Rust binary tests, all 16 serial real-process native smokes, and all 188 existing Node Playground CLI regression tests. The PHP matrix passed all 21 PHP 7.4–8.5 cases: base/parallel/resource behavior, real Xdebug DBGp handshakes, and real Redis/Memcached TCP round trips. All 14 checked-in component digests match
php-assets.json; isolated PHP 7.4 base and extended rebuilds are byte-identical.The lifecycle-disabled installed-package gate passed against the final staged tarball, including package-boundary checks, concurrent acquisition, offline reuse, both-profile prewarm, packaged WordPress/Blueprint/snapshot, ESM/CJS/bin, and live proxy/control smokes. Its SHA-256 is
1c6e1d3c664de030f81ef5dde0b9c7fac736d8b53e1323ca79795c5bf46543b5; the matching compressed Linux x64 host fixture is645b6787e8c9cb890ed919c0f07bfe02f1a80900e0ac236d0be3879552590d94.The external Studio harness uses the same tarball and native-host fixture in two modes:
Both final reports have status
PASS. They cover the unchanged Studio child contract and an ordinary builtstudioCLI: create/start/stop/restart, fresh WordPress installation, frontend, admin, post editor, Site Editor, phpMyAdmin, concurrent HTTP/WP-CLI WAL access, in-flight cancellation and recovery, Blueprints, PHP 7.4–8.5 selection/reopen, and Xdebug. Node 24 additionally performs real Redis and Memcached set/get/delete operations through both HTTP andstudio wpfor every PHP version. This is local integration evidence; the Studio harness is not part of this repository's CI.The tables below are the latest matched WAL benchmark set. They were collected before the PHP-version and extension artifact update, so they describe the current concurrency/WAL design rather than the exact final component binaries. Six workers were pinned to six physical cores; the load generator used six other cores.
PSS is the primary memory comparison because summed RSS counts PHP-FPM's shared libraries and shared OPcache mapping once per child. Final-head CI at
9a437319is green: 62 checks passed and 3 intentionally skipped, including all six native OS/architecture jobs, the PHP WASI component build, and all five macOS prerelease build/assembly/exact-final checks.