[PHP-WASM] Route PHP popen through wasm wrappers - #3951
Merged
Conversation
This was referenced Jul 8, 2026
bgrgicak
commented
Jul 8, 2026
| "php_init_config",\ | ||
| "zend_register_constant",\ | ||
| "zend_register_ini_entries_ex",\ | ||
| "php_mail",\ |
Collaborator
Author
There was a problem hiding this comment.
This change is unrelated to the popen changes. We need to add support for PHP Mail to Asyncify for the SMTP project and by adding it here we are avoiding a recompile.
bgrgicak
marked this pull request as ready for review
July 8, 2026 08:14
Collaborator
Author
|
These changes were already approved in #3486 and I plan to merge it when CI passes tests. |
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.
Motivation for the change, related issues
The previous
popen/pcloseimplementation used single global variables (wasm_popen_last_pidandwasm_pclose_ret) to track the spawned process PID and exit code. This meant concurrent writablepopen()calls would clobber each other's state, producing wrong exit codes or closing the wrong process.Implementation details
Linker-level wrapping replaces macro patching
This PR uses
--wrap=popenand--wrap=pcloselinker flags to redirect allpopen()/pclose()calls in the compiled C code to__wrap_popen/__wrap_pclose, which delegate towasm_popen/wasm_pclose. Forpclose, handles not created bywasm_popenfall through to the real libcpclose.Per-fd PID tracking instead of globals
Replaces
wasm_popen_last_pidandwasm_pclose_retwith an fd-to-pid mapping stored in the existing JSPHPWASM.processTable. Three new Emscripten library functions manage the mapping:js_popen_set_pid_for_fd(fd, pid)— called bywasm_popenafter spawning a processjs_popen_get_pid_for_fd(fd)— called bywasm_pcloseto find which process to wait onjs_popen_clear_pid_for_fd(fd)— called bywasm_pclosebefore closing the fileThis allows multiple
popenhandles to be open simultaneously without state corruption.Emscripten library updates
Adds
__wrap_popen,__wrap_pclose, andzif_pcloseto the Asyncify import list and JSPI export list so the new wrapper functions can suspend correctly.Testing Instructions