Home › Developer Tools › PHP Online Compiler

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:

index.php
Ln 1, Col 1Ctrl + Enter to run · Tab indents 4 spaces
Starting…

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.

Advertisement
Advertisement

How to use the PHP Online Compiler

  1. Write or paste PHP in the editor, starting with <?php, or pick an example.
  2. Press Run code or Ctrl + Enter. The first run downloads the PHP runtime; later runs start quickly.
  3. Read the output, or switch to HTML preview when your script prints a web page.
  4. Fix errors by clicking a warning or fatal error under the output to jump to its line.
  5. 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

MessageDoes the script continue?Typical cause
Parse errorNo, nothing runsMissing semicolon, bracket or quote; unexpected token
Fatal error (Uncaught Error / TypeError)Stops at that lineUndefined function, wrong argument type, calling a method on null
WarningYesUndefined array key, undefined variable, foreach over a non-array
NoticeYesMinor issues such as converting an array to a string in some contexts
DeprecatedYesA 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, sprintf and printf, 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.

Related tools

PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.JSON to PHP ArrayConvert JSON to PHP array code (short [] or array()) and PHP arrays back to JSON.Online Python CompilerRun Python 3 in your browser with input(), numpy, pandas, charts and share links.JavaScript Online CompilerWrite and run JavaScript in your browser with a console, timing, error lines and share links.JSON EditorEdit JSON in a tree and as code side by side: add, rename, drag, change types, undo and download.Unzip FilesOpen and extract ZIP files online.RAR & 7z ExtractorOpen RAR, 7z and other archives online and extract files.Regex TesterTest and debug regular expressions live.File Info ViewerCheck file size, type, date and MD5/SHA hashes.SQLite ViewerOpen .db and .sqlite files in your browser, browse tables and run SQL queries.DOCX ViewerOpen and read Word .docx files in your browser, then print or save them as HTML.EPUB ReaderOpen and read EPUB e-books in your browser with pages, a table of contents and font controls.What Is My BrowserSee your browser, version, OS, engine, screen and which web features it supports.Font ViewerPreview TTF, OTF, WOFF and WOFF2 fonts with sample text, waterfall, glyphs and metadata.Markdown EditorWrite Markdown with a toolbar, live split preview, autosave and .md or HTML export.Regex Cheat Sheet75+ ready-to-use regex patterns for emails, URLs, IPs and dates, each with a live test box.JavaScript Keycode FinderPress any key to see its JavaScript key, code, keyCode, which, location and modifiers.QR Code ScannerScan QR codes with your camera or from an image and safely read the link or text.RAID CalculatorUsable capacity, efficiency and fault tolerance for RAID 0, 1, 5, 6, 10, 50 and 60 arrays.JSONPath TesterTest JSONPath expressions live: filters, slices, wildcards and recursive search, with matches highlighted.Mermaid Diagram EditorWrite Mermaid code and see flowcharts, sequence, Gantt and ER diagrams live. Export SVG or PNG.Country Codes ListSearch ISO 3166 alpha-2, alpha-3 and numeric country codes with calling codes and TLDs.CSS Selector TesterTest CSS selectors on your HTML: highlighted matches, match count and specificity.Git Cheat SheetSearchable Git command reference by task, with copy buttons and an undo/rename/fix wizard.HAR File ViewerOpen a .har file to see a waterfall timeline, headers, bodies, timings and size totals.jq PlaygroundRun jq filters on JSON in your browser with live output, flags and an example library.Markdown Cheat SheetInteractive Markdown syntax reference: edit every example and see the live rendered preview.Regex ExplainerPaste a regular expression and get a plain-English breakdown, railroad diagram and flag notes.XPath TesterTest XPath expressions on XML or HTML: highlighted matches, node paths, values and examples.EML File ViewerOpen .eml email files to read the message, headers and raw source and save attachments.Graphviz Online ViewerWrite Graphviz DOT code and render graphs live; switch layout engines, export SVG or PNG.Jupyter Notebook ViewerOpen .ipynb files and read code, Markdown, math, tables, plots and errors without Python.LaTeX Table GeneratorEdit a table like a spreadsheet or paste from Excel and get LaTeX tabular or booktabs code.Log File ViewerOpen huge log files with level colors, regex and time filters, JSON pretty-print and tail -f.Logic Gate SimulatorBuild logic circuits with AND, OR, NOT, XOR gates and flip-flops; see live outputs and truth tables.MSG File ViewerOpen Outlook .msg emails in your browser: sender, recipients, body, headers and attachments.Online Code EditorVS Code-style editor in your browser: tabs, 50+ languages, find/replace, autosave.Online Hex EditorOpen any file as hex and ASCII, edit bytes, search, inspect values and save the result.JMESPath TesterEvaluate JMESPath expressions against JSON live, the query language used by the AWS CLI.MongoDB Query TesterTest MongoDB find filters, projections and aggregation pipelines on sample JSON documents.Semantic Version CalculatorBump, compare, sort and test SemVer versions against npm ^, ~ and x ranges.XSLT TesterRun an XSLT 1.0 stylesheet on XML in your browser and see the output as HTML, XML or text.ASCII Diagram EditorDraw boxes, arrows and text on a character grid and copy plain-text diagrams for code and READMEs.DBF File ViewerOpen dBase .dbf files and shapefile tables, search and sort records, export CSV or XLSX.MBOX File ViewerOpen .mbox mail archives: list and search messages, read them, save attachments, export EML.MDB File ViewerOpen Access .mdb and .accdb databases in your browser: list tables, view rows, export CSV.Shapefile ViewerView zipped shapefiles on a map with the attribute table, then export to GeoJSON or CSV.PlantUML EditorWrite PlantUML and see sequence, class, activity and more diagrams live. Export SVG or PNG.Sorting Algorithm VisualizerWatch bubble, insertion, merge, quick, heap and radix sort step by step with live counters.Lottie ViewerOpen Lottie JSON or .lottie files to play, pause, scrub frames, change speed and see details.Diff ViewerPaste a git diff or .patch file and view it side by side or inline, with file navigation.EditorConfig GeneratorBuild an .editorconfig with indent, charset, line endings and trim rules per file pattern.Folder Compare ToolCompare two folders by file list, size and SHA-256 hash, then open a text diff of changed files.Glob Pattern TesterTest glob patterns like **/*.js, {a,b} and !exclusions against a list of file paths.
See all 53 Code Playgrounds & Testers →