-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHP SAPI module #107
Merged
Merged
PHP SAPI module #107
Conversation
This file contains 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
… issuing a warning
adamziel
added
[Type] Enhancement
New feature or request
[Feature] PHP.wasm
[Type] Developer Experience
labels
Jan 12, 2023
This was referenced Jan 12, 2023
PHP builds regenerated in 3a175a2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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 is this PR all about?
Introduces a PHP SAPI module that enables setting
$_POST
,$_SERVER
,php://input
and all the other PHP values from JavaScript.What problem does it solve?
Before this PR, most superglobal values were set by prepending code snippets like
$_SERVER['DOCUMENT_ROOT'] = ${JSON.stringify(documentRoot)};
every time some code was evaluated. Unfortunately, that technique couldn't populate everything, e.g.php://input
remained empty.How does it work?
PHP SAPI is used to integrate PHP with webservers and runtimes. A few SAPIs you might be familiar with are
php-cgi
,php-fpm
, andphp-cli
. A SAPI consumes the request information from the runtime, passes it to PHP, triggers the code execution, and passes the response back to the runtime.This PR introduces a WASM SAPI that accepts input information from JavaScript, sets up a PHP request, and passes a response back to JS. The most important changes are in the
php_wasm.c
file. The rest of the PR is adjusting the existing codebase to the new way of working with PHP.Briefly speaking, the SAPI module exposes a few setters like
wasm_set_query_string
orwasm_add_SERVER_entry
and awasm_sapi_handle_request()
function that triggers the request execution. The output information are written to/tmp/stdout
,/tmp/stderr
, and/tmp/headers.json
by the C module and read by the PHP JavaScript class.Because the request body and the query string are parsed by the same PHP internal functions as they would on a webserver, array syntax like
settings[newsletter]=1
is handled correctly.One surprising thing is the ability to set arbitrary
$_FILES
entries withwasm_add_uploaded_file
. This is because JavaScript typically has access to any uploadedFile
objects and it would be wasteful to re-serialize them only so that PHP can parse them all over again. Withwasm_add_uploaded_file
you can first write the uploaded files to the filesystem and then simply let PHP know about their existence.Solves #103