-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# 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`, and `php-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` or `wasm_add_SERVER_entry` and a `wasm_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 with `wasm_add_uploaded_file`. This is because JavaScript typically has access to any uploaded `File` objects and it would be wasteful to re-serialize them only so that PHP can parse them all over again. With `wasm_add_uploaded_file` you can first write the uploaded files to the filesystem and then simply let PHP know about their existence. Solves #103
- Loading branch information
Showing
24 changed files
with
1,954 additions
and
1,016 deletions.
There are no files selected for viewing
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.