Lumaktaw patungo sa pangunahing content

PHP.js JavaScript module

PHP.js JavaScript module

The php.js file generated by the WebAssembly PHP build pipeline is not a vanilla Emscripten module. Instead, it's an ESM module that wraps the regular Emscripten output and adds some extra functionality.

Here's the API it exposes:

// php.wasm size in bytes:
export const dependenciesTotalSize = 5644199;

// php.wasm filename:
export const dependencyFilename = 'php.wasm';

// Run Emscripten's generated module:
export default function (jsEnv, emscriptenModuleArgs) {}

The generated JavaScript module is not meant for direct use. Instead, it can be consumed through the PHP class:

// In Node.js:
const php = new PHP(await loadNodeRuntime('8.0'));

// On the web:
const php = new PHP(await loadWebRuntime('8.0'));

Both platform loaders return a runtime ID accepted by the PHP class from @php-wasm/universal, which provides the shared API across environments. See PHP.wasm packages for how the shared API, platform adapters, and version-specific binaries fit together.

Loading the PHP runtime

The loadPHPRuntime() function handles the PHP initialization pipeline. In particular, it:

  • Instantiates the Emscripten PHP module
  • Wires it together with the data dependencies and loads them
  • Ensures it all happens in the correct order
  • Waits until the entire loading sequence is finished