2023-03-29 07:46:27 -04:00
2022-07-17 17:18:50 -04:00
2020-08-26 17:27:26 -04:00
2023-03-26 19:08:00 -04:00
2023-10-11 13:55:00 -04:00
2023-04-03 15:32:45 -04:00
2021-11-05 02:26:09 -04:00
2022-05-23 03:01:52 -04:00
2020-08-26 15:44:55 -04:00
2023-10-11 13:55:00 -04:00
2023-10-11 13:55:00 -04:00
2020-08-26 15:44:55 -04:00
2020-08-22 00:53:41 -04:00
...
2023-10-10 16:26:18 -04:00
2023-10-10 12:23:08 -04:00
2021-11-06 19:09:45 -04:00
2023-10-10 13:50:39 -04:00
2023-10-08 16:21:17 -04:00
2020-08-22 04:03:06 -04:00
2023-10-11 13:55:00 -04:00
2020-08-22 06:02:28 -04:00
2023-10-10 13:50:39 -04:00
2023-10-10 13:52:23 -04:00

PIB: PHP in Browser (and Node.js) aka php-wasm

php-wasm Apache-2.0 Licence Badge

CircleCI Size

v0.0.7 - Remodernizing.

changelog

Examples

Quickstart

Inline PHP

Include the php-tags.js script from Unpkg:

<script async type = "text/javascript" src = "https://www.unpkg.com/php-wasm/php-tags.mjs"></script>

And run some PHP right in the page!

<script type = "text/php">
<?php phpinfo();
</script>

Getting Started

Install with npm:

$ npm install php-wasm

Static Assets:

You'll need to add the following postinstall script entry to your package.json to ensure the static assets are available to your web application. Make sure to replace public/ with the path to your public document root if necessary.

{
  "scripts": {
    "postinstall": [
      "cp node_modules/php-wasm/php-web.* public/"
    ]
  },
}

If you're using a more advanced bundler, use the vendor's documentation to learn how to move the files matching the following pattern to your public directory:

./node_modules/php-wasm/php-web.*

Usage

Using php-wasm is easy.

Automatic

Use the php-tags.js script to run inline PHP:

<script async type = "text/javascript" src = "https://www.unpkg.com/php-wasm/php-tags.mjs"></script>

<script type = "text/php">
	<?php vrzno_run('alert', ['Hello, world!']);
</script>

Manual

First, grab an instance of the object:

const PHP = require('php-wasm/PhpWeb').PhpWeb;
const php = new PHP;

or, in es6:

import { PhpWeb as PHP } from 'php-wasm/PhpWeb';
const php = new PHP;

Then, add an output listener:

php.addEventListener('output', (event) => {
	console.log(event.detail);
});

Be sure to wait until your WASM is fully loaded, then run some PHP:

php.addEventListener('ready', () => {
	php.run('<?php echo "Hello, world!";');
});

Get the result code of your script with then():

php.addEventListener('ready', () => {
	php.run('<?php echo "Hello, world!";').then(retVal => {
		// retVal contains the return code.
	});
});

Persistent Memory

So long as php.refresh() is not called from Javascript, the instance will maintain its own persistent memory.

<?php
// Run this over and over again...
print ++$x;

See the example in action here

Accessing the DOM

The DOM may be accessed via the 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


// 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 . '"' );

Building From Source

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.

make

php-wasm is a fork of oraoto/PIB...

Run PIB

S
Description
No description provided
Readme
91 MiB
0 Stars 1 Watchers 0 Forks
Languages
PHP 39.3%
JavaScript 23.9%
Makefile 19.4%
HTML 10.8%
CSS 4.3%
Other 2.3%