-
Notifications
You must be signed in to change notification settings - Fork 120
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 in nodejs #8
Comments
You can buile PIB for NodeJS by changing the build config to: emcc -O3 \
-s WASM=1 \
-s EXPORTED_FUNCTIONS='["_pib_eval", "_php_embed_init", "_zend_eval_string", "_php_embed_shutdown"]' \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall"]' \
-s TOTAL_MEMORY=134217728 \
-s ASSERTIONS=0 \
-s INVOKE_RUN=0 \
-s ENVIRONMENT=node \
-s MODULARIZE=1 \
libs/libphp7.a pib_eval.o -o out/php.html Some changes:
Then you can run PHP in NodeJS like this: let em_module = require('./php.js')
// No <?php tag
// Output is line-buffered, so EOL is needed
let code =`
echo "Hello from PHP" . PHP_EOL;
`
em_module().then((em) => {
em.ccall('pib_eval', 'number', ["string"], [code])
}) |
Exactly what is needed but without cli :( |
@domozhirov To run PHP CLI is also possible: Enable CLI, notice the emconfigure ./configure \
--disable-all \
--disable-cgi \
--enable-cli \
--disable-rpath \
--disable-phpdbg \
--without-pear \
--without-pcre-jit \
--with-layout=GNU \
--enable-embed=static \
--enable-bcmath \
--enable-json \
--enable-ctype \
--enable-tokenizer Build: emmake make
# rename to *.o, so that emcc recognize it
mv sapi/cli/php sapi/cli/php.o
# compile to WASM
emcc -O3 \
-s WASM=1\
-s ENVIRONMENT=node \
-s TOTAL_MEMORY=134217728 \
sapi/cli/php.o -o out/php.html Run: $ cd out
$ node php.js -v
PHP 7.3.0alpha3 (cli) (built: Aug 9 2018 10:19:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
$ node php.js -m
[PHP Modules]
bcmath
Core
ctype
date
json
pcre
Reflection
SPL
standard
tokenizer
[Zend Modules]
$ node php.js -r 'echo "Hello";'
Hello
However, it can't run PHP file directly, source code must be read from stdin:
|
How could you make it so pib could read files? Like through include? I’d like to try to run a PHP application to generate HTML client side. |
Hello. How to use PIB in nodejs or how to make PIN (php in nodejs)
The text was updated successfully, but these errors were encountered: