About this PHP playground
This is a PHP compiler you can use straight away. Write PHP in the editor, press Run, and the output appears next to it: everything your script echoes, every warning, notice and error with its line number, and how long it took.
Your code runs on PHP 8.1 from the command line, in an isolated sandbox on our servers, so it behaves as it would with php main.php on your own machine. It is free, with nothing to install and no account needed.
What you can run
- PHP 8.1, running one file per run, saved as
main.php. - Standard library only. PHP's built-in functions for strings, arrays, maths, dates, JSON and regular expressions (preg_match and friends) are all there, with classes, interfaces, enums and closures. The mbstring extension and database drivers are not. There is no package installer, and programs have no network access.
- Limits: 10 seconds and 256 MB of memory per run. Output past 64 KB is cut off, code can be up to 64 KB and input up to 16 KB.
- Fair use: 5 runs a minute and 50 a day without an account, 10 a minute when you are signed in.
Reading input
Open the Input box under the editor and type what your script should read. fgets(STDIN) reads the next line, newline included, so trim it. With the box empty, or once every line is read, it returns false.
$name = trim(fgets(STDIN));
Frequently asked questions
Is this online PHP compiler free?
Yes. There is no sign-up and no limit on how much you can write. Signed-out visitors get a quick, usually invisible bot check when they press Run, and a fair-use cap of 5 runs a minute and 50 a day. Signing in raises it to 10 runs a minute.
Which version of PHP does it run?
PHP 8.1 on Linux, run from the command line. Enums, readonly properties, match, named arguments, arrow functions and the nullsafe operator all work. Features added after 8.1, such as readonly classes and typed class constants, do not.
Can I run a web page, a form or Laravel?
No. Your script runs once from the command line, as php main.php, not behind a web server, so there is no $_GET, $_POST or session, and no Composer packages or network. Any HTML outside the <?php tags is printed as it is, which shows you what a page would send to the browser.
Why do I see warnings and deprecation notices?
Every error level is switched on, as it is on a development machine, and sent to the error output so it does not mix with what your script prints. A warning such as an undefined variable does not stop the script; a fatal error does.
How do I read input in the PHP playground?
Type it in the Input box under the editor, then read it from STDIN: fgets(STDIN) returns one line, fscanf(STDIN, "%d", $n) reads a number, and stream_get_contents(STDIN) reads everything at once. Stick to these rather than mixing them with readline().
Why did my script stop with a time-out?
Each run gets 10 seconds and 256 MB of memory. A program that goes past either is stopped. The usual cause is a while loop whose condition never turns false.
Is my code saved or shared?
Your code is kept in your own browser so it is still there next time, and nowhere else. When you press Run it is sent to our code runner, run once in a sandbox, and thrown away. We do not store it or show it to anyone.