All Projects → oraoto → Pib

oraoto / Pib

Licence: apache-2.0
PHP in Browser (powered by WebAssembly)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Pib

Wasmtime
Standalone JIT-style runtime for WebAssembly, using Cranelift
Stars: ✭ 6,413 (+888.14%)
Mutual labels:  webassembly, wasm
Wasm And Rust
WebAssembly and Rust: A Web Love Story
Stars: ✭ 476 (-26.66%)
Mutual labels:  webassembly, wasm
Camaro
camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser pugixml, one of the fastest XML parser around.
Stars: ✭ 438 (-32.51%)
Mutual labels:  webassembly, wasm
Dotnet Webassembly
Create, read, modify, write and execute WebAssembly (WASM) files from .NET-based applications.
Stars: ✭ 535 (-17.57%)
Mutual labels:  webassembly, wasm
Uno
Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
Stars: ✭ 6,029 (+828.97%)
Mutual labels:  webassembly, wasm
Jwebassembly
Java bytecode to WebAssembly compiler
Stars: ✭ 426 (-34.36%)
Mutual labels:  webassembly, wasm
Vim.wasm
Vim editor ported to WebAssembly
Stars: ✭ 4,915 (+657.32%)
Mutual labels:  webassembly, wasm
Lucet
Lucet, the Sandboxing WebAssembly Compiler.
Stars: ✭ 4,006 (+517.26%)
Mutual labels:  webassembly, wasm
Webassemblyjs
Toolchain for WebAssembly
Stars: ✭ 566 (-12.79%)
Mutual labels:  webassembly, wasm
Awesome Wasm Runtimes
A list of webassemby runtimes
Stars: ✭ 490 (-24.5%)
Mutual labels:  webassembly, wasm
Ink
Parity's ink! to write smart contracts
Stars: ✭ 407 (-37.29%)
Mutual labels:  webassembly, wasm
Astro
A fun safe language for rapid prototyping and high performance applications
Stars: ✭ 588 (-9.4%)
Mutual labels:  webassembly, wasm
Bootstrapblazor
A set of enterprise-class UI components based on Bootstrap and Blazor
Stars: ✭ 403 (-37.9%)
Mutual labels:  webassembly, wasm
Graphql Client
Typed, correct GraphQL requests and responses in Rust
Stars: ✭ 620 (-4.47%)
Mutual labels:  webassembly, wasm
Rustynes
👾 An NES emulator by Rust and WebAssembly
Stars: ✭ 399 (-38.52%)
Mutual labels:  webassembly, wasm
Asmble
Compile WebAssembly to JVM and other WASM tools
Stars: ✭ 466 (-28.2%)
Mutual labels:  webassembly, wasm
Awesome Yew
😎 A curated list of awesome things related to Yew / WebAssembly.
Stars: ✭ 353 (-45.61%)
Mutual labels:  webassembly, wasm
Wac
WebAssembly interpreter in C
Stars: ✭ 372 (-42.68%)
Mutual labels:  webassembly, wasm
Genact
🌀 A nonsense activity generator
Stars: ✭ 5,109 (+687.21%)
Mutual labels:  webassembly, wasm
Zwitterion
A web dev server that lets you import anything*
Stars: ✭ 514 (-20.8%)
Mutual labels:  webassembly, wasm

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

Build Status PHP

v0.0.2 - Gaining Momentum

Examples

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

Once the library is included in the page, you can run PHP right from a script tag! The src attribute is also supported for non-inline scripts.

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

Manual

First, grab an instance of the object:

const php = new ( require('php-wasm/Php').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 = '[email protected]' . date('h:i:s');

// Grab the current title.
$oldTitle = vrzno_eval('document.title');

// Change the document title.
vrzno_eval('document.title = "' . $newTitle . '"' );

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

Run PIB

Firefox is recommended for better user experience.

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

Using Emscripten SDK (emsdk) manually

Steps:

  • Setup emsdk (>= 1.38.11), see Installation Instructions
  • Run bash configure.sh
  • Run bash build-objects.sh
  • Run bash build.sh to build the web binary

Acknowledgements

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].