Skip to content
Devtoolry

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

  1. Write or paste PHP, including the opening <?php tag.
  2. Add stdin input if your script reads it.
  3. Click Run and read the output.

Example

Loop over an associative array

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

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