Run PHP in the Browser with PHP em: WebAssembly‑Powered Development Stack
PHP em is a WebAssembly‑based, single‑page PHP development stack that lets you write, test, and run PHP code directly in the browser or as a desktop app, offering an integrated IDE, virtual file system, multi‑version support, database extensions, and GitHub integration.
What is PHP em?
PHP em is a WebAssembly‑based single‑page PHP development stack that runs PHP code directly in the browser. It provides a full development environment including a code editor, virtual file system (VFS), SQLite support, and multi‑version PHP testing (PHP 8.0‑8.4 and the master branch). An Electron‑based desktop build enables offline development on Linux, macOS, and Windows.
Main Features
Browser IDE : Built‑in syntax‑highlighting editor with real‑time execution for supported PHP versions.
Virtual File System (VFS) : In‑memory file system that supports project import/export (ZIP), persistent storage via IndexedDB/FileSystem API, and POSIX‑style file operations.
GitHub Integration : Load projects or Gists directly from GitHub using SSH‑key authentication to avoid API rate limits.
Database & Extensions : Built‑in SQLite, GD/JPEG/PNG image processing, XML/DOM, zlib, bz2 and other common extensions.
Desktop Application : Electron package for Linux (AppImage/ZIP), macOS (DMG/ZIP), and Windows (portable, installer, ZIP).
Quick Start
Online Usage
Open the online PHP em environment (URL listed on the GitHub page).
Select the desired PHP version from the dropdown.
Write PHP code in the editor.
Press Ctrl+Enter or click “Run Code” to see the output instantly.
Desktop Installation
Download the appropriate package for your OS and start the Electron app with the --no-sandbox flag.
Linux : AppImage or ZIP for x64/arm64.
macOS : DMG or ZIP for x64/arm64.
Windows : Portable, installer, or ZIP for x64.
Example launch command:
./em.AppImage --no-sandbox # Linux exampleSample Code
PHP snippet to run in the editor:
<?php
echo "Hello from PHP in WebAssembly!";
?>JavaScript API integration example:
const result = Module.invoke('<?php echo "Hello from PHP!"; ?>');
console.log(result); // Output: "Hello from PHP!"Use Cases
Learning & Education
No need to install XAMPP/WAMP; beginners can start coding immediately.
Sandboxed environment safe for experiments and tutorials.
Multiple PHP versions allow compatibility testing.
Prototyping & Testing
Validate algorithms or concepts quickly.
Switch PHP versions without altering the host system.
Development & Debugging
Portable, isolated development environment.
Built‑in virtual browser to test forms, sessions, and HTTP requests.
Advanced Features
Virtual Browser
The virtual browser runs PHP web applications in a simulated environment, eliminating the need for a real server while allowing testing of form handling, session management, and HTTP requests.
Project Management
File/Folder Operations : Create and organize projects inside the VFS.
Import/Export : Supports ZIP archives and efficient VFS images created with compressed contiguous buffers.
GitHub Integration : Directly import repositories or Gists.
Example command to create a VFS image:
php-em-vfs.js --mode create --in /path/to/my/files --out /tmp/my.vfsiMulti‑Version Support
Supports PHP 8.0, 8.1, 8.2, 8.3, 8.4 and the master development branch, enabling cross‑version behavior testing.
Architecture & Technology
WebAssembly : Compiles PHP’s C source into efficient browser‑runnable code.
Emscripten : Toolchain that produces the WebAssembly binary.
Virtual File System : Simulates POSIX file operations with random access and optional compression.
Service Workers : Enable the virtual browser functionality.
IndexedDB / FileSystem API : Provide persistent storage for the VFS.
Why Choose PHP em?
PHP em removes the configuration overhead of traditional PHP stacks, offering a zero‑configuration, cross‑platform environment suitable for:
Students and beginners learning PHP.
Developers prototyping and testing across multiple PHP versions.
Online or offline web application development.
Conclusion
PHP em brings full PHP development into browsers and desktop environments via WebAssembly and a virtual file system. The tool is ideal for learning, rapid prototyping, testing, and production development without any local server setup. Repository: https://github.com/krakjoe/em
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
