b2KIT

PHP Playground (WASM)

Run PHP code directly in the browser using php-wasm with standard output and error display.

Tested tool guide Tested browser tools Checked August 16, 2026

What PHP Playground (WASM) does, with a checked example

Server-side code in a serverless page: the PHP engine itself is compiled to WebAssembly and runs inside your browser. Your script executes locally, echo and print land in an output area, while warnings, fatal errors and parse errors appear in a separate error area. Paste a complete script that starts with the <?php tag and run it. The usual surprise: this is PHP's command-line interpreter, not a web server, so $_GET and $_POST are empty, header() does nothing useful, and files written to disk vanish on reload.

Worked example

A concrete input and expected output from the current implementation.

Input

<?php
$total = 0;
for ($i = 1; $i <= 5; $i++) {
    $total += $i * $i;
}
echo "Sum of squares 1..5 = $total";

Expected output

Sum of squares 1..5 = 55

The loop adds 1^2 + 2^2 + 3^2 + 4^2 + 5^2 = 1 + 4 + 9 + 16 + 25 = 55, and echo prints the interpolated string exactly as written into the output area. Small enough to verify by hand, and it exercises the full path: script, loop, string interpolation, stdout capture.

How the result is produced

1

How execution works

On first load the page fetches a PHP engine compiled to WebAssembly; the engine is the download, not your code. The pasted script is written to a virtual file in an in-memory filesystem and executed by that engine inside the browser, so nothing you type is ever sent to a server. Echoed output and the engine's diagnostics (warnings, fatals, parse errors) are captured separately into their own areas.

2

The runtime is CLI PHP, not Apache

Execution runs under PHP's CLI SAPI: there is no HTTP request, so superglobals such as $_GET, $_POST and $_SERVER are empty or minimal, and web-SAPI functions such as header() behave differently. The extension set is fixed by the WASM build, so calling an absent one raises an undefined-function error. file_put_contents() writes to an in-memory filesystem that vanishes on reload, and the build has no network bridge, so remote URL calls fail.

Good uses

  • Testing a PHP snippet, such as a regex, an array sort or a date calculation, on a machine with no PHP installed, without setting up a local server just to evaluate one function.
  • Isolating a bug from a larger script: paste the smallest fragment that fails and read the exact warning or fatal the engine raises, before touching the real server.
  • Checking whether a behavior depends on the PHP version, since the WASM build ships its own PHP release, which may be newer or older than the one on your host.

Limits and checks

  • It is not a web server. Code that relies on $_GET, $_POST, cookies or sessions silently sees empty values or behaves unlike Apache or nginx; a script that works on the server can fail here, and one that works here can fail when deployed.
  • The interpreter is the exact PHP release the WASM build bundles. Syntax or functions newer than that release produce parse errors or undefined-function errors, so verify version-dependent features against the version you actually deploy.
  • Output and errors are separate areas, and a single run can fill both: a fatal error stops the script, but anything echoed earlier stays in the output area. Check the error area before trusting the output, since its presence is not proof the run succeeded.

Common questions

Can I test form handling with $_POST and $_SESSION here?

Not meaningfully. The engine runs your code as a CLI script with no incoming HTTP request: request superglobals are empty, sessions and cookies do not work as on a server, and header() output is discarded. Use the playground for pure PHP logic, such as strings, arrays, math and file-format work, and test request handling on your real server.

Is my code uploaded, and do I need an internet connection to run it?

No upload: the interpreter runs in the browser and your code never leaves the page. The only network dependency is fetching the WebAssembly engine on first load; once the browser has cached it, the playground runs offline. There is no hidden server-side state, database or shared storage behind the scenes.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools