npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kenorb/php-wasm

v0.0.5-a

Published

Run PHP right in the browser.

Downloads

4

Readme

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

php-wasm Apache-2.0 Licence Badge

CircleCI Size

v0.0.4 - Revisiting.

changelog

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

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

  • php-wasm and makefile contributed by @seanmorris
  • The Web UI is based on Rust Playground.