oraoto / pib Goto Github PK
View Code? Open in Web Editor NEWPHP in Browser (powered by WebAssembly)
Home Page: https://oraoto.github.io/pib/
License: Apache License 2.0
PHP in Browser (powered by WebAssembly)
Home Page: https://oraoto.github.io/pib/
License: Apache License 2.0
After running bash build.sh
I'm get this error:
/bin/bash /home/rodion/pib/php-7.3.0beta2/libtool --silent --preserve-dup-deps --mode=compile /home/rodion/emsdk/emscripten/1.38.12/emcc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -IZend/ -I/home/rodion/pib/php-7.3.0beta2/Zend/ -DPHP_ATOM_INC -I/home/rodion/pib/php-7.3.0beta2/include -I/home/rodion/pib/php-7.3.0beta2/main -I/home/rodion/pib/php-7.3.0beta2 -I/home/rodion/pib/php-7.3.0beta2/ext/date/lib -I/home/rodion/pib/php-7.3.0beta2/TSRM -I/home/rodion/pib/php-7.3.0beta2/Zend -fvisibility=hidden -DZEND_SIGNALS -c /home/rodion/pib/php-7.3.0beta2/Zend/zend_string.c -o Zend/zend_string.lo
/home/rodion/pib/php-7.3.0beta2/Zend/zend_string.c:23:11: fatal error: 'valgrind/callgrind.h' file not found
# include "valgrind/callgrind.h"
^~~~~~~~~~~~~~~~~~~~~~
1 error generated.
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting
Makefile:787: recipe for target 'Zend/zend_string.lo' failed
make: *** [Zend/zend_string.lo] Error 1
mkdir: cannot create directory ‘out’: File exists
ERROR:root:libs/libphp7.a: No such file or directory ("libs/libphp7.a" was expected to be an input file, based on the commandline arguments provided)
cp: cannot stat 'out/php.wasm': No such file or directory
cp: cannot stat 'out/php.js': No such file or directory
cp: cannot stat 'out/php.data': No such file or directory
Done
emcc 1.38.12
OS: Ubuntu 18.04
Thanks
oraoto/pib$ make
Downloading and patching SQLite
--2022-02-27 00:45:54-- https://sqlite.org/2020/sqlite-amalgamation-3330000.zip
Resolving sqlite.org (sqlite.org)... 2600:3c00::f03c:91ff:fe96:b959, 45.33.6.223
Connecting to sqlite.org (sqlite.org)|2600:3c00::f03c:91ff:fe96:b959|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2417079 (2.3M) [application/zip]
Saving to: ‘sqlite-amalgamation-3330000.zip’
sqlite-amalgamation-3330000.zip 100%[===================================================================================================>] 2.30M 1.26MB/s in 1.8s
2022-02-27 00:45:56 (1.26 MB/s) - ‘sqlite-amalgamation-3330000.zip’ saved [2417079/2417079]
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 33, in <module>
sys.exit(load_entry_point('docker-compose==1.27.4', 'console_scripts', 'docker-compose')())
File "/usr/bin/docker-compose", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/lib/python3.9/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 981, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'compose.cli'; 'compose' is not a package
make: *** [Makefile:44: third_party/sqlite3.33-src/sqlite3.c] Error 1
Title says it all.
Usual way to use extension with php is to copy compiled extension into extension_dir
and then adding extension=ext-name.o
to php.ini
.
Is there any way to include some custom extension into pib bundle?
I'm just started to learn something about emacsen, so I yet can't figure solution by myself.
Something like #8 but for Python.
There is already Python library for executing WebAssembly binaries. How to use it with PHP?
and 100% CPU usage
To make sure all PHP langauge features are supported.
Hello,
I thinks this project is great! I wanted to tweak PHP for a long time, but couldn't really do it. I have a fun project to compile different languages to wasm and put them together on the same page, I've called it the Wheel of WebAssembly.
To use the PHP part, I need to change the way you build the wasm - I need it to be modularized as I have other emscripten-built sources as well. I have done these changes in my fork and I was wondering it you were interested in pushing them to you as a PR? :-)
Best,
Boyan
If i click on Run it, after some seconds my Chrome Tab crashes
Video Link
Hi, I’d like to ask you a question. PIB doesn’t work in Safari 12 because of never resolved promise, that returns from WebAssembly.instantiate, which used as fallback. Safari 12 ( and also 13 beta) doesn’t have WebAssembly.instantiateStreaming.
Promise only resolves in Safari 13 beta and all works.
I managed to find out that the problem is in WebAssembly.Memory, which instance used as property in second argument of WebAssembly.instantiate method. Promise had resolved when i removed WebAssembly.Memory instance from properties (it fails later, but anyway).
I tried to change the amount of allocated memory, but it had no effect
Maybe you have some thoughts about workaround of this problem?
Does pib supports implementation of composer packages?
I built a wasm with option allowing run it in web worker and it works fine. But when i run script like this:
echo 1; sleep(5); echo 2;
i getting "12" output only after 5 seconds. I considering is there any way (any possibly build config) to make php interactive? I've tried to build it with CLI enabled (#8 (comment)), but i don't know how to use it properly in browser.
Hello. How to use PIB in nodejs or how to make PIN (php in nodejs)
Can we utilize zend_execute
to evaluate opcode directly?
Some benefits:
If possible, we can remove the lexer and parser entirely.
FYI "Hello, World" and "phpinfo()" examples crash tab on Firefox 90.
I tried in several ways but failed.
Is there any other good way?
#include "sapi/embed/php_embed.h"
#include "zend.h"
#include "zend_interfaces.h"
#include <emscripten.h>
#include <stdlib.h>
/*int EMSCRIPTEN_KEEPALIVE pib_eval(char *code) {
int ret = 0;
putenv("USE_ZEND_ALLOC=0");
PHP_EMBED_START_BLOCK(0, NULL)
ret = zend_eval_string(code, NULL, "PIB");
PHP_EMBED_END_BLOCK()
return ret;
}*/
zend_class_entry *default_exception_ce;
char * exception_error(zval *exception, int severity TSRMLS_DC) {
char * result;
zend_class_entry *ce_exception = Z_OBJCE_P(exception);
if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
zval *str, *file, *line;
zval rv;
EG(exception) = NULL;
zend_call_method(&exception, ce_exception, NULL, "__tostring", 10, &str, 0, NULL, NULL TSRMLS_CC);
if (!EG(exception)) {
if (Z_TYPE_P(str) != IS_STRING) {
result = "Exception::__toString() must return a string";
} else {
zend_update_property_string(default_exception_ce, exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name : Z_STRVAL_P(str) TSRMLS_CC);
}
}
zval_ptr_dtor(&str);
if (EG(exception)) {
/* do the best we can to inform about the inner exception */
if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
file = zend_read_property(default_exception_ce, EG(exception), "file", sizeof("file")-1, 1 TSRMLS_CC, &rv);
line = zend_read_property(default_exception_ce, EG(exception), "line", sizeof("line")-1, 1 TSRMLS_CC, &rv);
} else {
file = NULL;
line = NULL;
}
result = "Uncaught in exception handling during call to __tostring()";
}
str = zend_read_property(default_exception_ce, exception, "string", sizeof("string")-1, 1 TSRMLS_CC, &rv);
file = zend_read_property(default_exception_ce, exception, "file", sizeof("file")-1, 1 TSRMLS_CC, &rv);
line = zend_read_property(default_exception_ce, exception, "line", sizeof("line")-1, 1 TSRMLS_CC, &rv);
result = "Uncaught %s\n thrown";
} else {
size_t n = snprintf(NULL, 0, "Uncaught exception '%s'", ce_exception->name);
result = malloc(n + 1);
snprintf(result, n + 1, "Uncaught exception '%s'", ce_exception->name);
}
return result;
}
char * EMSCRIPTEN_KEEPALIVE pib_eval(char *code) {
char *result = NULL;
putenv("USE_ZEND_ALLOC=0");
PHP_EMBED_START_BLOCK(0, NULL)
zend_first_try {
zend_eval_string(code, NULL, "PIB" TSRMLS_CC);
} zend_catch {
if (PG(last_error_message)) {
result = strdup(PG(last_error_message));
free(PG(last_error_message));
PG(last_error_message) = NULL;
}
/* if (PG(last_error_message)) {
result = strdup(PG(last_error_message));
free(PG(last_error_message));
PG(last_error_message) = NULL;
}
if (!result && EG(exception)) {
result = exception_error(EG(exception), E_ERROR TSRMLS_CC);
EG(exception) = NULL;
}*/
if(!result){
result="No Error.";
}
} zend_end_try();
PHP_EMBED_END_BLOCK()
return result;
}
I guess that people want to use it like this way:
<script type="text/php">
// php code here
</script>
so, make it as generic as possible and register it to packagist.org.
Rather than instruct people how to build it, it is more reasonable to provide the output. If my output is the same output as yours, why do i have to build my self while we have the same needs: a common php engine. Let your output be the "official" one.
I want to use xmlwriter and SimpleXML extensions.
Is there a way to enable those extensions?
I've installed pib as package by:
npm install php-wasm
And I've loaded an instance of the object as per README (into NextJS):
const PHP = require('php-wasm/PhpWeb').PhpWeb;
const php = new PHP;
However I've got the following error:
ReferenceError: window is not defined
What's the best approach to define reference to window
?
Call Stack
Object.<anonymous>
node_modules/php-wasm/PhpWeb.js (54:1)
Module._compile
node:internal/modules/cjs/loader (1101:14)
Object.Module._extensions..js
node:internal/modules/cjs/loader (1153:10)
Module.load
node:internal/modules/cjs/loader (981:32)
Function.Module._load
node:internal/modules/cjs/loader (822:12)
Module.require
node:internal/modules/cjs/loader (1005:19)
require
node:internal/modules/cjs/helpers (102:18)
Object.php-wasm/PhpWeb
.next/server/pages/index.js (130:18)
__webpack_require__
.next/server/webpack-runtime.js (33:42)
Affected line (in node_modules/php-wasm/PhpWeb.js):
if (window && document) {
Is there any solution to lower memory spike on startup? Currently it spikes up to 3GB, then lowers back to 300MB a few seconds later, but this spike can crush page on weak devices
Would it be possible to run PHP with WebAssembly System Interface?
WebAssembly is an assembly language for a conceptual machine, not a physical one. This is why it can be run across a variety of different machine architectures.
Just as WebAssembly is an assembly language for a conceptual machine, WebAssembly needs a system interface for a conceptual operating system, not any single operating system. This way, it can be run across all different OSs.
This is what WASI is — a system interface for the WebAssembly platform.
We aim to create a system interface that will be a true companion to WebAssembly and last the test of time. This means upholding the key principles of WebAssembly — portability and security.
It provides portable and secure way to run WASM with system interface. It is also sandboxed.
Hey, Oraoto!
We are so impressed by your contribution to VisualDL and have some good news for you. Can u contact me at [email protected]? Thanks
Currently, the README includes a howto to publish the js files to include and sentence "Once the library is included in the page".
The sentence should be extended with an example of html code with the exact includes needed.
I'm trying to load PhpWeb in NextJS app, but it's failing as below:
Unhandled Runtime Error
RuntimeError: abort(RuntimeError: abort(both async and sync fetching of the wasm failed). Build with -s ASSERTIONS=1 for more info.). Build with -s ASSERTIONS=1 for more info.
Call Stack
abort
node_modules/php-wasm/php-web.js (9:11689)
eval
node_modules/php-wasm/php-web.js (9:13352)
Version: [email protected]
I'm loading <Drupal/>
component by:
const Drupal = dynamic(() => import("../components/Drupal"), {ssr: false});
where Drupal class is defined as:
export default class Drupal extends React.Component {
constructor(props) {
super(props);
}
componentDidUpdate(prevProps, prevState) {
}
async componentDidMount() {
const PhpWeb = (await import('php-wasm/PhpWeb')).PhpWeb;
const php = new PhpWeb;
}
render() {
return (
<div className={styles.drupal}>
Drupal
</div>
)
}
}
Any ideas why this error happens? In php-web.js
file?
To operate DOM through wrapped EM_ASM_ interface
reference: http://webassemblycode.com/webassembly-cant-access-dom/
Hi, beginner here.
Can you tell me if it is possible, through this library, to run a simple script that uses this library: https://github.com/nfephp-org/sped-da ?
The script I need to work is one like this: https://github.com/nfephp-org/sped-da/blob/master/examples/nfe/danfe.php, the only difference is that the $xml will be passed by the application.
So far I have been using a server to do this, but it would be really cool if it worked on the client side, after all performance is not a priority and I just want to cut my costs.
It would be great to use PHP in Iodide. It also uses languages (currently only Python) that are compiled to WebAssembly so it should not be hard to do this.
For details how to do this see iodide-project/iodide#1637.
are there any plans to update the PHP version, for example 8 or 8.1.
I've tried to compile PHP 8.1.6 with latest Emscripten and am getting the following error:
shared:ERROR: /src/php-8.1.6/Zend/asm/make_x86_64_sysv_elf_gas.S: Input file has an unknown suffix, don't know what to do with it!
Makefile:893: recipe for target 'Zend/asm/make_x86_64_sysv_elf_gas.lo' failed
make: *** [Zend/asm/make_x86_64_sysv_elf_gas.lo] Error 1
could anyone help with this? I'll gladly invest some time into updating this project, I really like the concept of PHP WASM. Thanks!
......
Build complete.
Don't forget to run 'make test'.
error: undefined symbol: getdtablesize
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
error: undefined symbol: getgrnam
error: undefined symbol: popen
Error: Aborting compilation due to previous errors
ERROR:root:'/root/emsdk/node/8.9.1_64bit/bin/node /root/emsdk/emscripten/tag-1.38.13/src/compiler.js /tmp/tmpqr0XyG.txt /root/emsdk/emscripten/tag-1.38.13/src/library_pthread_stub.js' failed (1)
Currently, the patch skip php_readdir_r
function entirely.
Example code:
<?php
echo "foo\nbar";
it prints foobar
and it's not about html ignoring newline, the output is "foobar" in inspector.
I also see great potential of how this could be used, as JavaScript has been reputable for its security issues. As a result, other methods are being sought out to harden websites. Looking through the code on the README
, it appears that to run the PHP script in the browser, it requires a little JS. Even though this, in of itself, is absolutely incredible for it to be client-sided, I was wondering if any work-arounds or alternatives have been proposed for this project in the long run.
How to reproduce:
Run this code about 31 times:
<?php
exit(0);
Hello everyone,.
I would like to test pib with header("http://google.com"); but it seems empty?
How do I check?
I never knew that php in wasm. Nice idea - It looks like embedding binary / script into websites - if webspace has not php and mysql than they evade with wasm. That is nice idea!
I have tested with Ubuntu 18.04 without php7.2
I thought wordpress should "embed" in wasm than they don't worry to protect if hackers try to hack to wasm files because wasm is protected file for any websites, right?
I have found before C# in wasm mono.wasm = finish!
c++/c in wasm = finish
php in wasm = finish but sometimes can't work with include or header()
js / ts in wasm ????
ruby or python in wasm ????
perl, lua or any scripts in wasm ????
Is that something you'd be interested in a PR for? php embed differs from a regular CLI in that it doesn't provide these (but echo
works)
I have this working in a fork - https://github.com/TysonAndre/phan-demo/blob/79d6df9950789ebf54cf3c798f772df8a76e887e/pib_eval.c#L16-L54
phar
file on disk. https://tysonandre.github.io/phan-demo/Alternately, a regular define+fopen in pure php before the script in question may work more reliably.
Could be php wasm compile with icu for using awesome php intl library in client side ?
I'd love to know what the terms of reuse were on this code. I'd hope for something Apache-like but even the GPL would be cool.
long time php fan here.
have no direct use of this, but i love it!
Hi
I tried to build the WASM File with the build.sh
but it ends with
warning: unresolved symbol: getdtablesize
warning: unresolved symbol: getgrnam
warning: unresolved symbol: posix_spawn_file_actions_adddup2
warning: unresolved symbol: posix_spawn_file_actions_destroy
warning: unresolved symbol: posix_spawn_file_actions_init
Done
but it seems not to work.
I got the menu with the Button LOADING but nothing more happens
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.