Skip to content

Commit 9c7d797

Browse files
authored
CLI and networking support (#119)
### Description Adds support for CLI SAPI and networking in node.js: ``` > npm run build > node ./build-cli/php-cli.js -r 'echo "Hello from PHP !";' Hello from PHP ! > node ./build-cli/php-cli.js -r 'echo substr(file_get_contents("https://wordpress.org"), 0, 16);' <!DOCTYPE html> > node ./build-cli/php-cli.js -r 'echo phpversion();' 8.2.0-dev > PHP=5.6 node ./build-cli/php-cli.js -r 'echo phpversion();' 5.6.40 ``` ### Highlights: * Networking is supported (including MySQL and HTTPS) * Switching PHP versions is supported. * [Most WordPress PHPUnit tests pass](#111). The failures are caused by missing extensions and a few misconfigured settings * PHP Interactive mode is supported but [the arrow keys don't work](#118) * `wp-cli` works ### In broad strokes: * CLI SAPI is compiled with libedit (readline replacement) and ncurses. * Network calls are asynchronous. Emscripten's Asyncify enables calling asynchronous code from synchronous code. TCP sockets are shimmed with a WebSocket connection to a built-in proxy server running on localhost. It supports data transfer, arbitrary connection targets, and setting a few TCP socket options. * PHP's OpenSSL uses the same CA certs as Node.js * PHP 5.6 is patched to work with OpenSSL 1.1.0 and many other small patches are introduced. For more details, see [patches overview](#119 (comment)), Dockerfile, and `phpwasm-emscripten-library.js` ### Future work: * PHP Interactive server isn't supported yet. Adding support is a matter of making the incoming connection polling non-blocking using Asyncify. * Use a more recent OpenSSL version * [Better support for CLI interactive mode](#118)
1 parent 9d777f4 commit 9c7d797

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+68553
-814
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/**/*
22
build/*
33
packages/*/build*/*
4+
src/php-wasm/wasm/build-assets/*

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
node_modules
55
package-lock.json
66
build/*
7+
build-cli/*
78
build-api
89
build-wp
910
build-php

build-cli/.gitkeep

Whitespace-only changes.

build-cli/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "php-cli",
3+
"version": "0.1.4",
4+
"description": "PHP CLI via WebAssembly. Part of WordPress Playground.",
5+
"main": "php-cli.js",
6+
"author": "The WordPress contributors",
7+
"contributors": [
8+
{
9+
"name": "Adam Zielinski",
10+
"email": "[email protected]",
11+
"url": "https://github.com/adamziel"
12+
}
13+
],
14+
"license": "Apache-2.0",
15+
"dependencies": {
16+
"ws": "^8.12.0"
17+
},
18+
"bin": "php-cli.js",
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/WordPress/wordpress-playground"
22+
},
23+
"homepage": "https://developer.wordpress.org/playground"
24+
}

build-cli/php.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error_reporting=E_ALL
2+
display_errors=1
3+
html_errors=1
4+
display_startup_errors=On
5+
log_errors=1
6+
always_populate_raw_post_data=-1
7+
upload_max_filesize=2000M
8+
post_max_size=2000M
9+
disable_functions=proc_open,popen,curl_exec,curl_multi_exec
10+
allow_url_fopen=On
11+
session.save_path=/home/web_user
12+
implicit_flush=1
13+
output_buffering=0

build/php-5.6.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)