Replace no-op spawn handler with native child_process.spawn bridge#3057
Open
Replace no-op spawn handler with native child_process.spawn bridge#3057
Conversation
00e4b38 to
848a3be
Compare
Collaborator
📊 Performance Test ResultsComparing 8eba4b7 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
The createNoopSpawnHandler unconditionally replaced PHP process spawning with a handler that immediately exits with code 1, silently breaking proc_open, exec, shell_exec, popen, and system calls. This replaces it with a handler that bridges to Node.js child_process.spawn, which php-wasm's setSpawnHandler already supports directly. Studio is a local development tool where PHP already has host filesystem access via createNodeFsMountHandler mounts, so process spawning is consistent with the existing trust model. Fixes: #3044 See also: #2519
848a3be to
877b5f9
Compare
Author
|
We need this to hit MCP via WP-CLI. |
Pass nativeSpawn: true to RunCLIArgs in wordpress-server-child.ts so PHP's proc_open(), shell_exec(), and exec() can spawn host processes when the site is running via the daemon. This complements the createNativeSpawnHandler() in run-wp-cli-command.ts (which handles the fallback path when no daemon is running). Depends on WordPress/wordpress-playground#3481 adding nativeSpawn to RunCLIArgs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
CI NoteThe lint (typecheck) failure is expected — this PR depends on WordPress/wordpress-playground#3481, which adds the |
gcsecsey
approved these changes
Apr 13, 2026
Contributor
gcsecsey
left a comment
There was a problem hiding this comment.
Thank you for creating this fix @chubes4, these changes make sense to me.
I patched the changes from WordPress/wordpress-playground#3481, and tested running the wp --info command and checking the output about the installed MySQL.
| trunk | this branch |
|---|---|
![]() |
![]() |
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.


Summary
createNoopSpawnHandler(which immediately exits with code 1) withcreateNativeSpawnHandlerthat bridges to Node.jschild_process.spawnproc_open,exec,shell_exec,popen, andsystemfunctionality in Studio's WP-CLI environmentsetSpawnHandleralready supports receiving achild_process.spawn-compatible function directly — the infrastructure was there, Studio just opted outFixes #3044
Motivation
The no-op handler silently breaks any PHP code that spawns processes. This affects:
wp --infocan't detect MySQL/MariaDB binary,wp db exportfailsproc_opento spawn MCP servers, completely broken in Studioexec()orproc_open()silently gets nothing backStudio is a local development tool where PHP already has host filesystem access via
createNodeFsMountHandlermounts. Process spawning is consistent with that existing trust model.Test plan
Tested against a local Studio site by building the CLI from source (
npm run cli:build) and comparing patched vs unpatched behavior:wp --info(the command from #2519):/opt/homebrew/bin/mariadbmariadb from 12.1.2-MariaDB, client 15.2 for osx10.20 (arm64)shell_exectest:proc_opentest (what php-mcp-client uses):Regression — basic WP-CLI commands still work:
wp --version→WP-CLI 2.12.0wp core version→6.9.4wp --info→ full output with MySQL binary now detectedAI disclosure
Per WordPress AI Guidelines:
AI assistance: Yes
Tool: Claude Code (Claude Opus 4.6)
Used for: Researching the php-wasm spawn handler API, tracing the
SpawnHandlertype through@php-wasm/universaland@php-wasm/utilto confirmchild_process.spawncompatibility, writing the replacement, and running verification tests. All code reviewed and validated by the author.