Online PHP Compiler
Run PHP 8.4 code online and see the output instantly, with stdin input and mbstring. PHP runs in your browser with WebAssembly, so your code stays private.
Runs in your browser · Nothing uploadedFree · No sign-up
Something not working, or missing a feature? Send feedback
About the PHP Compiler
The PHP Compiler runs PHP 8.4 in your browser, compiled to WebAssembly, so your code never leaves your device. It is useful for testing snippets, functions and modern PHP syntax, with stdin input for scripts that read it. Use it as a PHP online compiler or a quick PHP tester: run PHP code online and see the output in a second.
Your code runs in an isolated Web Worker in your browser, so it never leaves your device.
How to use the PHP Compiler
- Write or paste PHP, including the opening <?php tag.
- Add stdin input if your script reads it.
- Click Run and read the output.
Example
Input
<?php
$prices = ['apple' => 1.2, 'pear' => 0.8];
foreach ($prices as $fruit => $price) {
printf("%s: %.2f\n", $fruit, $price);
}
echo array_sum($prices), PHP_EOL;Result
apple: 1.20 pear: 0.80 2
array_sum returns the float 2.0, which echo prints as 2. Use number_format() or printf() to control decimals.
Common mistakes
- Forgetting <?php. Without the opening tag PHP prints your code as plain text instead of running it.
- Expecting a web request. The script runs on its own, not behind a web server, so $_GET, $_POST and request headers are empty. Set the values in code to test the logic.
- Long-running scripts. Execution stops at the time limit. Infinite loops and sleep() calls end with a timeout instead of output.
Works well with the PHP Compiler
- PHP Formatter: tidy the code into PSR-12 style first.
- JSON to PHP Array: turn JSON test data into a PHP array.
- Python Compiler: try the same idea in Python.
Frequently asked questions
Is it safe to run untrusted code?
Code runs in an isolated Web Worker with a time limit and no network access, separate from the page and your data on this site.
Which PHP version is used?
PHP 8.4, so named arguments, match expressions, enums, readonly properties and property hooks are available.
Can I read input with fgets(STDIN)?
Yes. Text in the stdin box is passed to the script, so fgets(STDIN) and stream_get_contents(STDIN) read it line by line.
Which extensions are available?
The core extensions plus mbstring: bcmath, calendar, ctype, date, exif, filter, hash, json, libxml, pcre, PDO, random, Reflection, session, SPL and tokenizer. Network and system extensions such as curl, openssl and mysqli are not available in the browser.
Is my code uploaded?
No. PHP is compiled to WebAssembly and runs in a Web Worker in your browser. The runtime (about 5 MB) downloads on the first run and is cached.
Can I run PHP without XAMPP or a web server?
Yes. PHP 8.4 runs in your browser with WebAssembly, so you can test functions, arrays and string handling without installing XAMPP, WAMP or PHP itself. Output from echo and print_r appears in the output panel.
Is PHP compiled or interpreted?
PHP compiles your script to opcodes and runs them immediately in the Zend engine, with no separate build step, so it behaves like an interpreted language. "PHP compiler" is just the name most people search for.
Can I connect to MySQL from the online PHP compiler?
No. The sandbox has no network access, so mysqli and PDO cannot reach a database server. To practise SQL, use the SQL playground and keep the PHP code for the logic around it.
Guides and tutorials
- Programming Languages
How to Format PHP Code Online: Beautify, Indent and Follow PSR-12
Format PHP code online: paste messy PHP, get consistent indentation and spacing, learn what PSR-12 requires and when to use Prettier, PHP-CS-Fixer or phpcbf.
· 4 min read
- Code Quality & Workflow
Prettier for PHP: Format PHP Code with @prettier/plugin-php
How to use Prettier for PHP: install @prettier/plugin-php, set up .prettierrc, choose braceStyle and phpVersion, format on save and check PHP formatting in CI.
· 7 min read
Related tools
JavaScript Compiler
Run JavaScript online in an isolated browser sandbox. See console output, errors and execution time instantly, with top-level await and stdin input.
TypeScript Compiler
Compile and run TypeScript online. Your code is type-checked with the official compiler in strict mode, then runs in a sandboxed worker in your browser.
Python Compiler
Run Python 3 code online with the full standard library and stdin input. It runs in your browser with Pyodide (WebAssembly), so your code stays on your device.
C Compiler
Compile and run C code online with Clang 21, a GCC-compatible compiler: pick C89 (ANSI C), C99, C11, C17 or C23 and add stdin input. Your code stays private.
C++ Compiler
Run C++ code online for free: compile C++20 with Clang 21 and libc++, type stdin input and see the output. It runs in your browser, so your code stays private.
C# Compiler
Run C# code online with Roslyn and .NET 10: C# 14, top-level statements, LINQ, records and Console.ReadLine input, in your browser, so code stays private.