PHP Online Compiler
Write PHP and run it instantly in your browser. See the raw output or render it as a web page in the HTML preview, jump to the line of any warning or fatal error, and share your script with a link. No server and no sign-up.
Last updated:
PHP 8 runs on your device through php-wasm (the PHP interpreter compiled to WebAssembly). The first run downloads the runtime, about 10 MB, which your browser then caches. Your code is never uploaded.
How to use the PHP Online Compiler
- Write or paste PHP in the editor, starting with
<?php, or pick an example. - Press Run code or Ctrl + Enter. The first run downloads the PHP runtime; later runs start quickly.
- Read the output, or switch to HTML preview when your script prints a web page.
- Fix errors by clicking a warning or fatal error under the output to jump to its line.
- Share or save your script with Copy share link or Download.
How the PHP compiler runs your code
On a normal website, a request reaches a web server, the server hands the .php file to the PHP engine, and the engine's output is sent back as the page. Here the same engine, compiled to WebAssembly, runs inside your browser in a background worker. Each run starts a fresh interpreter, so functions and classes from the previous run do not cause "Cannot redeclare" errors, and a stuck loop can be stopped without freezing the page. Everything your script echoes, prints or outputs outside the <?php ?> tags is collected and shown in the Output tab or rendered in the HTML preview.
PHP error levels at a glance
| Message | Does the script continue? | Typical cause |
|---|---|---|
| Parse error | No, nothing runs | Missing semicolon, bracket or quote; unexpected token |
| Fatal error (Uncaught Error / TypeError) | Stops at that line | Undefined function, wrong argument type, calling a method on null |
| Warning | Yes | Undefined array key, undefined variable, foreach over a non-array |
| Notice | Yes | Minor issues such as converting an array to a string in some contexts |
| Deprecated | Yes | A feature that will be removed in a later version, such as passing null to a non-nullable built-in parameter |
What works in browser PHP
- Works: strings and multibyte functions, arrays, math, JSON, PCRE regular expressions, DateTime and time zones, classes, interfaces, traits, enums, generators, closures, exceptions,
sprintfandprintf, output buffering. - Limited: file functions use a temporary in-memory file system that is reset on every run;
sleep()counts toward the time limit. - Not available: MySQL or other database servers, outgoing HTTP requests (curl,
file_get_contents('https://…')), mail(), request data such as$_GET,$_POST, cookies and sessions.
Tip: to debug a value, use var_dump($x) for types and lengths or print_r($x) for a compact view of arrays, and wrap it in <pre> when you look at the HTML preview.
Frequently asked questions
How can PHP run without a server?
PHP is an interpreter written in C. The php-wasm project compiles that interpreter to WebAssembly, a format every modern browser can execute, so this page runs the real PHP engine on your own computer. Your script is parsed to opcodes and executed locally, and the output is shown on the page instead of being sent by a web server.
Which PHP version is used?
A PHP 8 build provided by php-wasm; the exact version (for example 8.2.x) is shown in the status bar once the runtime has loaded and is also available as PHP_VERSION in your code. Syntax from PHP 8.0 to 8.2 such as match expressions, enums, readonly properties, named arguments and the nullsafe operator works.
Why does my code print as plain text?
PHP only executes code between <?php and ?> tags; everything outside them is sent to the output unchanged. Start the file with <?php. A closing ?> at the end is optional and best left out in pure PHP files, because any whitespace after it becomes output.
What does the HTML preview show?
It renders whatever your script echoes as a web page in a sandboxed frame, so templates, tables and inline CSS look as they would in a browser. Scripts in the preview may run but cannot access this page. Use the Output tab to see the raw HTML source.
Can I use databases, sessions, $_GET or file uploads?
No. There is no web server or MySQL database in the browser, so superglobals such as $_GET, $_POST and $_SESSION are empty and network functions such as curl and file_get_contents with URLs are not available. Core extensions for strings, arrays, math, JSON, dates, regular expressions (PCRE) and classes work normally.
Why does my script stop after a TypeError but continue after a warning?
Warnings, notices and deprecations are reported and execution continues. Fatal errors, including uncaught exceptions such as TypeError, DivisionByZeroError or calls to undefined functions, stop the script at that line. Since PHP 8 many old warnings became TypeError or ValueError exceptions, which you can catch with try and catch.
Is my code private?
Yes. The PHP runtime is downloaded once from a public CDN and your code runs locally. Share links keep the code, compressed, after the # in the URL, which browsers never send to a server.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.