A modern PHP compiler written in Rust that compiles PHP to native machine code.
WarpPHP compiles a subset of PHP into optimized native executables using a custom SSA IR and LLVM backend. It explores ahead-of-time compilation as an alternative to traditional PHP interpreters.
⚠️ Experimental — WarpPHP currently supports a subset of PHP and is under active development. It is not a drop-in replacement for PHP-FPM or production PHP runtimes.
Traditional PHP deployments rely on interpreters and process managers such as PHP-FPM.
WarpPHP explores a different approach: ahead-of-time compilation, native binaries, and cloud-native execution.
The long-term vision is to modernize PHP infrastructure for:
- Serverless and edge computing
- Low-memory containers
- High-density workloads
- WebAssembly deployment
- Fast native PHP execution via LLVM
- Cloud-native deployment (tiny binaries, instant startup)
- Serverless optimization (WASI/WASM)
- Modern compiler infrastructure (SSA IR, optimization passes)
- Developer-friendly tooling and diagnostics
# Build the compiler (requires Rust + LLVM 20)
cargo build --release
# Compile PHP to a native executable
./target/release/warpphp build examples/fibonacci.php -o fib
./fib # → 55
# Compile with optimizations (constant folding, DCE, constant propagation + LLVM O2)
./target/release/warpphp build examples/hello.php -O -o hello
./hello # → 15
# Run PHP directly via JS backend (requires Node.js)
./target/release/warpphp run examples/hello.php
# Compile to JavaScript
./target/release/warpphp compile examples/hello.php
# Dump WarpPHP IR
./target/release/warpphp ir examples/hello.php -O
# Dump LLVM IR
./target/release/warpphp llvm-ir examples/hello.php -O
# Check for errors without compiling
./target/release/warpphp check examples/hello.php
# Dump AST / token stream
./target/release/warpphp ast examples/hello.php --pretty
./target/release/warpphp lex examples/hello.phpEarly benchmarks show promising native execution performance on recursive workloads:
| Metric | Native (WarpPHP) | Node.js (via JS backend) |
|---|---|---|
| fib(35) | ~37ms | ~89ms |
| Output binary size | 16KB | N/A |
| Startup time | ~1ms | ~50ms |
Benchmarks are preliminary and measured on a single machine. Reproducible benchmark suite coming soon.
- ✅ Variables (
$a = 5;) - ✅ Integers, floats, strings, booleans, null
- ✅ Arithmetic operators (
+ - * / % **) - ✅ String concatenation (
.) - ✅ Comparison operators (
== != === !== < > <= >=) - ✅ Logical operators (
&& || ! and or) - ✅ Bitwise operators (
& | ^ ~ << >>) - ✅ Assignment operators (
= += -= *= /= .= %=) - ✅ Increment/decrement (
++ --) - ✅
echostatement - ✅
if / elseif / else - ✅
whileloop - ✅
forloop - ✅ Functions (declaration + call, recursive)
- ✅ Type hints (int, float, string, bool, void, array)
- ✅
return,break,continue - ✅ Comments (
//,#,/* */) - ✅ Built-in functions (strlen, intval, abs, max, min, etc.)
PHP Source → Lexer → Parser → AST → Sema → IR → WarpPHP Opts → LLVM IR → Native Binary
↑ ↑
constant fold, DCE, LLVM O2 passes
constant propagation (mem2reg, inline, etc.)
| Crate | Purpose |
|---|---|
warp_ast |
AST nodes, spans, types, visitor pattern |
warp_lexer |
Single-pass tokenizer with span tracking |
warp_parser |
Pratt parser (expressions) + recursive descent (statements) |
warp_sema |
Semantic analysis, type inference, scope resolution |
warp_ir |
SSA IR, optimization passes (constant fold, DCE, constant prop) |
warp_codegen_js |
JavaScript code generation backend |
warp_codegen_llvm |
LLVM native code generation backend (via inkwell) |
warp_cli |
CLI binary (warpphp command) |
- Custom Pratt Parser — Same approach as rustc, V8, Clang. Superior error messages and extensibility.
- SSA-form IR — Alloca/store/load pattern (like LLVM's mem2reg). Enables powerful optimizations.
- Multi-pass optimization — Fixed-point iteration with pluggable Pass trait.
- LLVM backend — Full access to LLVM's optimization pipeline and native codegen.
- Multi-crate workspace — Parallel compilation, clear boundaries, testable in isolation.
- Span-based errors — Every AST node tracks source location for precise diagnostics.
WarpPHP IR (warpphp ir examples/hello.php -O):
define void @__main() {
entry:
%0 : i64 = const 5
%1 : i64 = alloca a : i64
%2 : void = store %1, %0
%3 : i64 = const 10
%4 : i64 = alloca b : i64
%5 : void = store %4, %3
%8 : i64 = const 15 ; ← constant folded at compile time
%9 : void = echo %8
ret void
}
LLVM IR (warpphp llvm-ir examples/fibonacci.php):
define i64 @fib(i64 %0) {
entry:
%n = alloca i64, align 8
store i64 %0, ptr %n, align 8
%load = load i64, ptr %n, align 8
%icmp = icmp sle i64 %load, 1
br i1 %icmp, label %if.then, label %if.merge
if.then:
ret i64 %load
if.merge:
%isub = sub i64 %load, 1
%call = call i64 @fib(i64 %isub)
%isub2 = sub i64 %load, 2
%call3 = call i64 @fib(i64 %isub2)
%iadd = add i64 %call, %call3
ret i64 %iadd
}- Custom lexer, Pratt parser, AST, semantic analysis
- JavaScript codegen backend
- 32 tests passing
- SSA-form Intermediate Representation
- Constant folding (arithmetic, comparisons, logical ops at compile time)
- Dead code elimination (removes unused instructions)
- Constant propagation (replaces loads from single-store-constant allocas)
- Fixed-point optimization loop (max 10 iterations)
- LLVM IR generation via
inkwell+ LLVM 20 - Native x86_64 binary output (16KB executables)
- C runtime integration (printf, malloc, strlen, strcat, pow)
- WarpPHP optimizations + LLVM O2 pass pipeline
- Promising early performance on recursive workloads
WarpPHP does not currently support:
- Classes, traits, interfaces, enums
- Arrays with string keys
- Closures / anonymous functions
- Composer autoloading
- Full PHP standard library
- Exceptions (try/catch)
- eval / include / require
- Garbage collection (memory is leaked in long-running programs)
- Laravel / Symfony / WordPress applications
See docs/php-subset.md for the full list.
- WASM binary output
- WASI support for serverless
- Edge runtime deployment (Cloudflare Workers, Fastly)
- Classes and objects
- Arrays with keys
- Closures / anonymous functions
- Match expressions
- Enums
- Garbage collector (generational)
- Async/await (fibers)
- HTTP server built-in
- JIT compilation tier
- Rust 1.85+ (via rustup)
- LLVM 20 dev (
sudo apt install llvm-20-dev libpolly-20-dev lld-20 zlib1g-dev libzstd-dev) - C compiler (
cc/gcc) - Node.js (optional, only for
warpphp run)
# Install dependencies (Ubuntu/Debian)
sudo apt install llvm-20-dev libpolly-20-dev lld-20 zlib1g-dev libzstd-dev build-essential
# Build
LLVM_SYS_201_PREFIX=/usr/lib/llvm-20 cargo build --release
# Run all tests
cargo test --all
# Compile and run an example natively
./target/release/warpphp build examples/fibonacci.php -O -o fib && ./fibBuilt and maintained by Vimatech. Created by Adel Zemzemi.
MIT