diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-10-25 17:34:54 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-10-25 17:57:23 +0900 |
| commit | 8101ba079b8b358a015f4de9acbfc85d89c335da (patch) | |
| tree | fdc57aedf9323c3a0d5e03979b530eca338a7a4c /files | |
| parent | 69c4159c6464937031e046eae3fc74045fe9fae0 (diff) | |
| download | phpstudy-157-slides-main.tar.gz phpstudy-157-slides-main.tar.zst phpstudy-157-slides-main.zip | |
Diffstat (limited to 'files')
| -rw-r--r-- | files/1 | 3 | ||||
| -rw-r--r-- | files/2 | 3 | ||||
| -rw-r--r-- | files/3 | 12 | ||||
| -rw-r--r-- | files/4 | 2 | ||||
| -rw-r--r-- | files/5 | 9 | ||||
| -rw-r--r-- | files/6 | 9 | ||||
| -rw-r--r-- | files/php-wasm.c | 8 |
7 files changed, 46 insertions, 0 deletions
@@ -0,0 +1,3 @@ +$ ./buildconf +$ ./configure +$ make @@ -0,0 +1,3 @@ +$ ./buildconf +$ emconfigure ./configure +$ emmake make @@ -0,0 +1,12 @@ +$ emconfigure configure \ + --disable-all \ + --disable-mbregex \ + --disable-fiber-asm \ + --disable-cli \ + --disable-cgi \ + --disable-phpdbg \ + --without-iconv \ + --without-libxml \ + --without-pcre-jit \ + --without-pdo-sqlite \ + --without-sqlite3 @@ -0,0 +1,2 @@ +$ EMCC_CFLAGS='-s ERROR_ON_UNDEFINED_SYMBOLS=0' \ + emmake make @@ -0,0 +1,9 @@ +$ emcc \ + -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ + -s ENVIRONMENT=node \ + -s INITIAL_MEMORY=16777216 \ + -s EXPORT_ES6=1 \ + -s INVOKE_RUN=0 \ + -s MODULARIZE=1 \ + -o php-wasm.js \ + php-wasm.o libphp.a @@ -0,0 +1,9 @@ +import PHPWasm from './php-wasm.js' + +const { ccall } = await PHPWasm(); +const result = ccall( + 'php_wasm_run', + 'number', ['string'], + [`echo "Hello, World!";`], +); +console.log(`exit code: ${result}`); diff --git a/files/php-wasm.c b/files/php-wasm.c new file mode 100644 index 0000000..c124af0 --- /dev/null +++ b/files/php-wasm.c @@ -0,0 +1,8 @@ +#include <emscripten.h> +#include <Zend/zend_execute.h> + +int EMSCRIPTEN_KEEPALIVE php_wasm_run(const char* code) { + zend_result result = + zend_eval_string_ex(code, NULL, "php.wasm code", 1); + return result == SUCCESS ? 0 : 1; +} |
