mirror of
https://github.com/bdnugget/php-wasm.git
synced 2026-11-07 09:07:28 +00:00
README updates.
This commit is contained in:
1 parent
d5e9d051a7
commit
d25432f739
11 files changed
+228
-91
No files matched your search
+1
-3
@@ -16,6 +16,4 @@ before_install:
|
||||
- docker run -dit --name emscripten -v $(pwd):/src trzeci/emscripten-ubuntu:latest bash
|
||||
|
||||
script:
|
||||
- docker exec -it emscripten apt-get update
|
||||
- docker exec -it emscripten apt-get install -y autoconf bison re2c
|
||||
- docker exec -it emscripten bash build.sh
|
||||
- make configure build-js build-web-bin
|
||||
@@ -1,21 +1,67 @@
|
||||
MIT License
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
Copyright (c) 2018-2020 Oraoto, 2020 Sean Morris
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
1. Definitions.
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution.
|
||||
|
||||
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions.
|
||||
|
||||
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks.
|
||||
|
||||
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability.
|
||||
|
||||
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability.
|
||||
|
||||
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -5,53 +5,58 @@ VRZNO_BRANCH:=master
|
||||
|
||||
.PHONY: configure build hooks build-js build-web-bin build-webview-bin build-node-bin build-shell-bin build-worker-bin clean
|
||||
|
||||
build: configure build-js build-web-bin build-webview-bin build-node-bin build-shell-bin build-worker-bin
|
||||
build: configure build-js build-webview-bin build-node-bin build-shell-bin build-worker-bin build-web-bin
|
||||
@ echo "Done!"
|
||||
|
||||
configure: php-src php-src/ext/vrzno
|
||||
docker-compose run emscripten-builder bash configure.sh
|
||||
@ docker-compose run emscripten-builder bash configure.sh
|
||||
|
||||
php-src:
|
||||
git clone https://github.com/php/php-src.git \
|
||||
--branch ${PHP_BRANCH} \
|
||||
--single-branch \
|
||||
@ git clone https://github.com/php/php-src.git \
|
||||
--branch ${PHP_BRANCH} \
|
||||
--single-branch \
|
||||
--depth 1;
|
||||
|
||||
php-src/ext/vrzno:
|
||||
cd php-src/ext \
|
||||
@ cd php-src/ext \
|
||||
&& git clone https://github.com/seanmorris/vrzno.git \
|
||||
--branch ${VRZNO_BRANCH} \
|
||||
--single-branch \
|
||||
--depth 1; \
|
||||
--single-branch \
|
||||
--depth 1; \
|
||||
|
||||
hooks:
|
||||
@ git config core.hooksPath githooks
|
||||
|
||||
build-objects: configure
|
||||
@ docker-compose run -e ENVIRONMENT=web emscripten-builder bash build-objects.sh
|
||||
|
||||
build-js:
|
||||
@ npm install; npx babel source --out-dir .
|
||||
@ npm install;
|
||||
@ npx babel source --out-dir .
|
||||
|
||||
build-image:
|
||||
docker-compose build
|
||||
@ docker-compose build
|
||||
|
||||
pull-image:
|
||||
docker-compose pull
|
||||
@ docker-compose pull
|
||||
|
||||
push-image:
|
||||
docker-compose push
|
||||
@ docker-compose push
|
||||
|
||||
build-web-bin:
|
||||
docker-compose run -e ENVIRONMENT=web emscripten-builder bash build.sh
|
||||
build-web-bin: build-objects
|
||||
@ docker-compose run -e ENVIRONMENT=web emscripten-builder bash build.sh
|
||||
|
||||
build-webview-bin:
|
||||
docker-compose run -e ENVIRONMENT=webview emscripten-builder bash build.sh
|
||||
build-webview-bin: build-objects
|
||||
@ docker-compose run -e ENVIRONMENT=webview emscripten-builder bash build.sh
|
||||
|
||||
build-node-bin:
|
||||
docker-compose run -e ENVIRONMENT=node emscripten-builder bash build.sh
|
||||
build-node-bin: build-objects
|
||||
@ docker-compose run -e ENVIRONMENT=node emscripten-builder bash build.sh
|
||||
|
||||
build-shell-bin:
|
||||
docker-compose run -e ENVIRONMENT=shell emscripten-builder bash build.sh
|
||||
build-shell-bin: build-objects
|
||||
@ docker-compose run -e ENVIRONMENT=shell emscripten-builder bash build.sh
|
||||
|
||||
build-worker-bin:
|
||||
docker-compose run -e ENVIRONMENT=worker emscripten-builder bash build.sh
|
||||
build-worker-bin: build-objects
|
||||
@ docker-compose run -e ENVIRONMENT=worker emscripten-builder bash build.sh
|
||||
|
||||
clean:
|
||||
docker-compose run emscripten-builder rm -rf php-src Php.js php-web.* php-webview.* php-node.* php-shell.* php-worker.*
|
||||
@ docker-compose run emscripten-builder rm -rf php-src Php.js php-web.* php-webview.* php-node.* php-shell.* php-worker.*
|
||||
@@ -1,10 +1,10 @@
|
||||
# php-wasm
|
||||
# php-wasm aka PIB
|
||||
|
||||
*[PIB](https://github.com/oraoto/pib), except its an NPM module.*
|
||||
|
||||
[](https://travis-ci.org/oraoto/pib) 
|
||||
|
||||
v.0.0.1c - humble beginnings
|
||||
v0.0.2 - Gaining Momentum
|
||||
|
||||
## Getting started
|
||||
|
||||
@@ -34,7 +34,7 @@ If you're using a more advanced bundler, use the vendor's documentation to learn
|
||||
.../node_modules/php-wasm/php-web.*
|
||||
```
|
||||
|
||||
### Usage
|
||||
## Usage
|
||||
|
||||
Using php-wasm is easy.
|
||||
|
||||
@@ -69,9 +69,43 @@ php.addEventListener('ready', () => {
|
||||
// retVal contains the return code.
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### Accessing the DOM
|
||||
|
||||
The DOM may be accessed via the [VRZNO](https://github.com/seanmorris/vrzno) php extension. This is specially for the browser allowing PHP to access Javascript via a C api. It comes preinstalled with php-wasm.
|
||||
|
||||
See the example in action [here](https://oraoto.github.io/pib/?code=%253C%253Fphp%250A%250A%2524oldTitle%2520%253D%2520NULL%253B%250A%2524newTitle%2520%253D%2520%27Changed%2540%27%2520.%2520date%28%27h%253Ai%253As%27%29%253B%250A%250A%252F%252F%2520Grab%2520the%2520current%2520title%250A%2524oldTitle%2520%253D%2520vrzno_eval%28%27document.title%27%29%253B%250A%250A%252F%252F%2520Change%2520the%2520document%2520title%250A%2524newTitle%2520%253D%2520vrzno_eval%28%27document.title%2520%253D%2520%2522%27%2520.%2520%2524newTitle%2520.%2520%27%2522%27%2520%29%253B%250A%250Aprintf%28%250A%2520%2520%2520%2520%27Title%2520changed%2520from%2520%2522%2525s%2522%2520to%2520%2522%2525s%2522.%27%250A%2520%2520%2520%2520%252C%2520%2524oldTitle%250A%2520%2520%2520%2520%252C%2520%2524newTitle%250A%29%253B%250A%250A%250A%252F%252F%2520Show%2520an%2520alert%250Avrzno_run%28%27alert%27%252C%2520%255B%27Hello%252C%2520World%21%27%255D%29%253B)
|
||||
|
||||
```php
|
||||
|
||||
// Show an alert with vrzno_run. Note the second param is an array of args.
|
||||
vrzno_run('alert', ['Hello, World!']);
|
||||
|
||||
$oldTitle = NULL;
|
||||
$newTitle = 'Changed@' . date('h:i:s');
|
||||
|
||||
// Grab the current title.
|
||||
$oldTitle = vrzno_eval('document.title');
|
||||
|
||||
// Change the document title.
|
||||
vrzno_eval('document.title = "' . $newTitle . '"' );
|
||||
|
||||
```
|
||||
|
||||
### Persistent Memory
|
||||
|
||||
So long as `php.refresh()` is not called, the instance will have its own persistent memory.
|
||||
|
||||
```php
|
||||
<?php
|
||||
// Run this over and over again...
|
||||
print $x++;
|
||||
|
||||
```
|
||||
|
||||
See the example in action [here](https://oraoto.github.io/pib/?persistent=1&code=%253C%253Fphp%250A%252F%252F%2520Run%2520this%2520over%2520and%2520over%2520again...%250Aprint%2520%2524x%252B%252B%253B)
|
||||
|
||||
# php-wasm is a fork of oraoto/PIB...
|
||||
|
||||
**[Run PIB](https://oraoto.github.io/pib/)**
|
||||
@@ -82,6 +116,8 @@ Firefox is recommended for better user experience.
|
||||
|
||||
+ [Hello, World](https://oraoto.github.io/pib/?code=%253C%253Fphp%250A%250Aecho%2520%2522Hello%252C%2520World%21%2522%253B)
|
||||
+ [JSON](https://oraoto.github.io/pib/?code=%253C%253Fphp%250A%250A%2524x%2520%253D%2520%255B%250A%2520%2520%2520%2522id%2522%2520%253D%253E%25201%2520%2520%250A%255D%253B%250A%250Avar_dump%28json_decode%28json_encode%28%2524x%29%29%29%253B%250A)
|
||||
+ [Persistent Data](https://oraoto.github.io/pib/?persistent=1&code=%253C%253Fphp%250A%252F%252F%2520Run%2520this%2520over%2520and%2520over%2520again...%250Aprint%2520%2524x%252B%252B%253B)
|
||||
+ [Access Javascript](https://oraoto.github.io/pib/?code=%253C%253Fphp%250A%250A%2524oldTitle%2520%253D%2520NULL%253B%250A%2524newTitle%2520%253D%2520%27Changed%2540%27%2520.%2520date%28%27h%253Ai%253As%27%29%253B%250A%250A%252F%252F%2520Grab%2520the%2520current%2520title%250A%2524oldTitle%2520%253D%2520vrzno_eval%28%27document.title%27%29%253B%250A%250A%252F%252F%2520Change%2520the%2520document%2520title%250A%2524newTitle%2520%253D%2520vrzno_eval%28%27document.title%2520%253D%2520%2522%27%2520.%2520%2524newTitle%2520.%2520%27%2522%27%2520%29%253B%250A%250Aprintf%28%250A%2520%2520%2520%2520%27Title%2520changed%2520from%2520%2522%2525s%2522%2520to%2520%2522%2525s%2522.%27%250A%2520%2520%2520%2520%252C%2520%2524oldTitle%250A%2520%2520%2520%2520%252C%2520%2524newTitle%250A%29%253B%250A%250A%250A%252F%252F%2520Show%2520an%2520alert%250Avrzno_run%28%27alert%27%252C%2520%255B%27Hello%252C%2520World%21%27%255D%29%253B)
|
||||
+ [Closures](https://oraoto.github.io/pib/?code=%253C%253Fphp%250A%250A%2524x%2520%253D%252010%253B%250A%250Afunction%2520run%28callable%2520%2524f%29%2520%257B%250A%2520%2520%2520%2520%2524f%28%29%253B%250A%257D%250A%250Arun%28function%2520%28%29%2520use%2520%28%2526%2524x%29%2520%257B%250A%2520%2520%2520%2520%2524x%2520%253D%25209%253B%250A%257D%29%253B%250A%250Avar_dump%28%2524x%29%253B%250A)
|
||||
+ [PCRE](https://oraoto.github.io/pib/?code=%253C%253Fphp%250A%250Apreg_match%28%27%252F%28foo%29%28bar%29%28baz%29%252F%27%252C%2520%27foobarbaz%27%252C%2520%2524matches%252C%2520PREG_OFFSET_CAPTURE%29%253B%250Aprint_r%28%2524matches%29%253B%250A)
|
||||
+ [Multi catch exception handling](https://oraoto.github.io/pib/?code=%253C%253Fphp%250A%250Atry%2520%257B%250A%2520%2520%2520%2520if%2520%28random_int%280%252C%252010%29%2520%253E%25205%29%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520throw%2520new%2520BadFunctionCallException%28%29%253B%250A%2520%2520%2520%2520%257D%2520else%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520throw%2520new%2520LengthException%28%29%253B%250A%2520%2520%2520%2520%257D%250A%257D%2520catch%2520%28BadFunctionCallException%2520%257C%2520LengthException%2520%2524ex%29%2520%257B%250A%2520%2520%2520%2520var_dump%28%2524ex%29%253B%250A%257D%250A)
|
||||
@@ -93,18 +129,24 @@ Firefox is recommended for better user experience.
|
||||
|
||||
### Using Docker
|
||||
|
||||
The quickest way to build PIB is by using Docker:
|
||||
The quickest way to build PIB is by using Make & Docker. Simply issue the `make` command after checking out the repo, and it will build.
|
||||
|
||||
```
|
||||
docker run --rm -it -v $(pwd):/src trzeci/emscripten-ubuntu:latest bash build.sh
|
||||
make
|
||||
```
|
||||
|
||||
### Setup Emscripten SDK (emsdk) manually
|
||||
|
||||
Steps:
|
||||
|
||||
1. Setup emsdk (>= 1.38.11), see [Installation Instructions](https://emscripten.org/docs/getting_started/downloads.html#installation-instructions)
|
||||
2. Run `bash build.sh`
|
||||
+ Setup emsdk (>= 1.38.11), see [Installation Instructions](https://emscripten.org/docs/getting_started/downloads.html#installation-instructions)
|
||||
+ Run `bash configure.sh`
|
||||
+ Run `bash build-objects.sh`
|
||||
+ Run `bash build.sh` to build the web binaries
|
||||
* Run ENVIRONMENT=shell to build the shell binaries (optional)
|
||||
* Run ENVIRONMENT=node to build the node binaries (optional)
|
||||
* Run ENVIRONMENT=worker to build the worker binaries (optional)
|
||||
* Run ENVIRONMENT=webview to build the webview binaries (optional)
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
|
||||
@@ -4,26 +4,23 @@ set -euxo pipefail;
|
||||
|
||||
pushd php-src
|
||||
|
||||
emmake make -j8
|
||||
|
||||
emcc -O3 -I . -I Zend -I main -I TSRM/ ../source/pib_eval.c -o pib_eval.o
|
||||
|
||||
emcc -O3 \
|
||||
--llvm-lto 2 \
|
||||
-s ENVIRONMENT=${ENVIRONMENT:-web} \
|
||||
EMCC_CORES=8 emcc -O3 \
|
||||
--llvm-lto 2 \
|
||||
-o ../out/php-${ENVIRONMENT:-web}.js \
|
||||
-s ENVIRONMENT=${ENVIRONMENT:-web} \
|
||||
-s EXPORTED_FUNCTIONS='["_pib_init", "_pib_destroy", "_pib_eval" "_pib_refresh", "_main", "_php_embed_init", "_php_embed_shutdown", "_php_embed_shutdown", "_zend_eval_string"]' \
|
||||
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "UTF8ToString", "lengthBytesUTF8"]' \
|
||||
-s MODULARIZE=1 \
|
||||
-s EXPORT_NAME="'PHP'" \
|
||||
-s TOTAL_MEMORY=134217728 \
|
||||
-s ASSERTIONS=0 \
|
||||
-s INVOKE_RUN=0 \
|
||||
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
|
||||
libs/libphp7.a pib_eval.o -o out/php-${ENVIRONMENT:-web}.js
|
||||
-s MODULARIZE=1 \
|
||||
-s EXPORT_NAME="'PHP'" \
|
||||
-s TOTAL_MEMORY=134217728 \
|
||||
-s ASSERTIONS=0 \
|
||||
-s INVOKE_RUN=0 \
|
||||
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
|
||||
--preload-file Zend/bench.php \
|
||||
libs/libphp7.a pib_eval.o
|
||||
|
||||
popd
|
||||
|
||||
cp ../out/php-${ENVIRONMENT:-web}.wasm \
|
||||
../out/php-${ENVIRONMENT:-web}.js \
|
||||
../out/php-${ENVIRONMENT:-web}.data \
|
||||
../
|
||||
cp ./out/php-${ENVIRONMENT:-web}.wasm \
|
||||
./out/php-${ENVIRONMENT:-web}.js \
|
||||
./
|
||||
+24
-2
@@ -4,9 +4,27 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>PIB: PHP in Browser</title>
|
||||
<style>@import url('/php-wasm/style.css')</style>
|
||||
<script src="//ajaxorg.github.io/ace-builds/src-min/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src = "/php-wasm/require1k.js" data-main = "./index"></script>
|
||||
<script type="text/javascript">
|
||||
// Allow the page to be served from any direcotry...
|
||||
const path = location.pathname.replace(/index.html$/, '');
|
||||
const script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = `${path}require1k.js`;
|
||||
|
||||
console.log(path);
|
||||
|
||||
script.setAttribute('data-main', `./index`);
|
||||
|
||||
document.head.append(script);
|
||||
|
||||
const style = document.createElement('style');
|
||||
style.type = 'text/css';
|
||||
|
||||
style.innerText = `@import url('${path}style.css')`;
|
||||
|
||||
document.head.append(style);
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -14,6 +32,10 @@
|
||||
<div class="playground">
|
||||
<div class="playground-header">
|
||||
<button id="run" disabled>Loading...</button>
|
||||
<label>
|
||||
<input id = "persist" type = "checkbox" >
|
||||
Persist
|
||||
</label>
|
||||
</div>
|
||||
<div class="playground-split-vertical">
|
||||
<div class="playground-editor">
|
||||
|
||||
+9
-1
@@ -1,5 +1,6 @@
|
||||
const inputArea = document.getElementById('input');
|
||||
const runButton = document.getElementById('run');
|
||||
const persistBox = document.getElementById('persist');
|
||||
const outputArea = document.getElementById('output').contentWindow.document;
|
||||
const defaultCode = '<?php phpinfo();';
|
||||
const editor = ace.edit("editor");
|
||||
@@ -23,7 +24,14 @@ const init = () => {
|
||||
var code = editor.getValue();
|
||||
var query = new URLSearchParams();
|
||||
|
||||
php.run(code);
|
||||
php.run(code).then(exitCode => {
|
||||
|
||||
if(exitCode || !persistBox.checked)
|
||||
{
|
||||
php.refresh();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (code.length < 1024)
|
||||
{
|
||||
|
||||
Binary file not shown.
+8
-1
@@ -69,4 +69,11 @@ body {
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #dedede;
|
||||
}
|
||||
}
|
||||
|
||||
label {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
||||
}
|
||||
+6
-5
@@ -1,8 +1,9 @@
|
||||
#!/bin/bash -eux
|
||||
|
||||
cp ./Php.js ./docs
|
||||
cp ./php-web.js ./docs
|
||||
cp ./php-web.wasm ./docs
|
||||
cp ./php-web.data ./docs
|
||||
|
||||
make
|
||||
|
||||
cp ./Php.js ./docs
|
||||
cp ./php-*.js ./docs
|
||||
cp ./php-*.wasm ./docs
|
||||
cp ./php-*.data ./docs
|
||||
|
||||
+25
-14
@@ -1,9 +1,3 @@
|
||||
const PhpNode = require('./php-node');
|
||||
const PhpShell = require('./php-shell');
|
||||
const PhpWeb = require('./php-web');
|
||||
const PhpWebView = require('./php-webview');
|
||||
const PhpWorker = require('./php-worker');
|
||||
|
||||
export class Php extends EventTarget
|
||||
{
|
||||
constructor(type = 'web')
|
||||
@@ -18,15 +12,32 @@ export class Php extends EventTarget
|
||||
this.onoutput = function () {};
|
||||
this.onready = function () {};
|
||||
|
||||
const binaryClasses = {
|
||||
webview : PhpWebView
|
||||
, worker: PhpWorker
|
||||
, shell : PhpShell
|
||||
, node : PhpNode
|
||||
, web : PhpWeb
|
||||
};
|
||||
let binaryClass;
|
||||
|
||||
const binaryClass = binaryClasses[type];
|
||||
switch(type)
|
||||
{
|
||||
case 'webview':
|
||||
binaryClass = require('./php-webview');
|
||||
break;
|
||||
|
||||
case 'worker':
|
||||
binaryClass = require('./php-worker');
|
||||
break;
|
||||
|
||||
case 'shell':
|
||||
binaryClass = require('./php-shell');
|
||||
break;
|
||||
|
||||
case 'node':
|
||||
binaryClass = require('./php-node');
|
||||
break;
|
||||
|
||||
case 'web':
|
||||
binaryClass = require('./php-web');
|
||||
break;
|
||||
}
|
||||
|
||||
binaryClasses[type];
|
||||
|
||||
this.binary = new binaryClass({
|
||||
|
||||
|
||||
Reference in new issue
Block a user