Elephc is a from-scratch, ahead-of-time compiler that turns a static subset of PHP into native machine code. It is written in Rust, MIT licensed, and its pitch was the subject of a SymfonyCon Warsaw talk this week. Guillaume Loulier posted the slides, “Pedal to the Metal: Compiling PHP to native code”, on Speaker Deck on 26 November. He is not a neutral third party. The project’s README lists him as a core contributor beside its creator, Vincenzo Petrucci of Illegal Studio, and he authored all five pull requests the slides show as in flight.
So I checked the talk against the repository, the docs and the project’s own changelog, and I timed the PHP half of the benchmark myself. The compiler is real and moving fast. The headline “15 to 20x faster than PHP with JIT” is a whole-process figure on three micro-benchmarks, and in my run most of PHP’s time was startup. The Symfony build the talk leads towards is not in a tagged release.

- What the talk argues
- How Elephc works
- The benchmark, and what I measured
- The hybrid route: compile one function, keep the rest
- Generics, and PHP’s own attempt
- DOOM, and “plain PHP”
- Where it stands
- The peers
- Trying it, and the CLI change
What the talk argues
Loulier’s starting point is that writing PHP means writing for an interpreter. A request goes through OPcache and the Zend VM, with the JIT only for hot paths. He calls the limit the interpreter wall and splits it into three parts:
- Speed. About 80% of an app is I/O-bound and 20% is CPU-bound: parsers, image processing, tight arithmetic.
- Reach. Off the server, PHP has to bring its engine with it. NativePHP embeds the interpreter, and otherwise PHP is API-only.
- Language. The type system, and generics in particular.
The two usual reflexes, he says, both leave PHP: write a C extension, or rewrite in Go or Rust. Elephc is offered as a third route. Slide 10 gives the lesson from earlier projects: HipHop, KPHP and PeachPie tried to replace PHP, and Elephc “sits next to it and compiles only what earns it”. The slides’ phrase is “Not a replacement. A scalpel.”

How Elephc works
The repository describes a conventional compiler pipeline: lexer, parser, goto lowering, resolver, type checker, optimiser, reachability pass, an SSA intermediate form called EIR, register allocation, assembly, then the host assembler and linker. The type checker is where generics are specialised. The project’s contract is “If it compiles, it’s native”: there is no Zend engine, VM or opcode fallback. The one exception is an experimental eval() that can embed an optional interpreter bridge the project calls Magician.

| Fact | What the project documents |
|---|---|
| Targets | macOS aarch64, Linux aarch64, Linux x86-64, and iOS arm64 and simulator for libraries only. No Windows, no WebAssembly. |
| Outputs | An executable, a C-ABI shared library with a generated header, a static library, or a PHP 8.5 extension. |
| Memory | A free-list and bump heap (128 MB by default, set with --heap-size), reference counting, copy-on-write arrays and a targeted cycle collector. |
| Known gap | Cycles through suspended Fiber or Generator frames are never collected, and raw or off-heap ownership cycles are outside the collector. |
| Size | Created on 21 March 2026, about 11,600 commits at the time of writing, 1,208 built-in functions and more than 20,000 tests, per elephc.dev. |
The benchmark, and what I measured
Slides 12 and 13 carry the headline: “15–20x faster than PHP with JIT, start to finish. Neck and neck with C.” The numbers come from Elephc’s own CI on 17 November, on macOS arm64 with PHP 8.5.12, median of three runs, whole-process wall time.
| Case | PHP with JIT | Elephc | C at -O2 | Speedup |
|---|---|---|---|---|
| sum_loop | 65.0 ms | 3.5 ms | 3.2 ms | 19x |
| array_sum | 61.0 ms | 3.9 ms | 3.2 ms | 15x |
| string_concat | 80.7 ms | 4.0 ms | 4.2 ms | 20x |
The slide’s own footer says these are micro-benchmarks, that PHP “pays startup, compile and JIT warm-up each run”, and that “your gain depends on your hot path, so measure it.” The repository’s benchmark README adds that Elephc’s times exclude its own compilation and linking. Those are fair disclosures, and they change what the figure means.
I ran the slide’s exact loop on PHP 8.3.6, the command-line build, on Linux x86-64 in my own environment. It prints 20000100000, matching the slide.
<?php
$sum = 0;
$i = 1;
while ($i <= 200000) {
$sum += $i;
$i += 1;
}
echo $sum . "\n";
26.5 ms
the loop, JIT on, median of 21 runs
24.4 ms
an empty script, same flags
10.3 ms
the loop, no OPcache or JIT
8.7 ms
an empty script, no OPcache or JIT
On my machine the loop itself costs about 2 ms either way, and the empty script accounts for nearly all of the rest. That is not Elephc’s hardware and not PHP 8.5.12, so my absolute numbers don’t test theirs. What it shows is the shape: with a loop this short, the whole-process gap between PHP and a native binary is mostly interpreter startup. The 15 to 20x is true of the process, and it says little about how fast either side runs a long computation.

I did not run Elephc. Building it here was blocked, so everything about its behaviour in this piece comes from the slides, the repository and its docs, and none of it from my own run.
The hybrid route: compile one function, keep the rest
The most practical idea in the talk is the extension output. Slide 14 shows a store-locator function marked with an #[Export] attribute, nearest(array $stores, float $lat, float $lng): int. The command elephc --emit phpext geo.php builds it into a real PHP extension, and one line, extension=geo.so, in php.ini loads it. The rest of the application stays ordinary PHP. The docs set the limits:
- It needs a PHP 8.5 development SDK, on Linux x86-64, Linux aarch64 or macOS aarch64. Thread-safe or not is allowed, provided the headers and the interpreter agree.
- Values that cross the boundary are int, float, bool, binary string, array, null, and objects of exported classes. Exported parameters need explicit types.
- Strings and arrays are copied in both directions at the boundary. A function that takes a large array and returns a small result pays for the copy in.
The same machinery runs the other way. With elephc extension add and a Rust crate called elephc-zend, which rewrites the Zend extension API in Rust, a compiled program can host existing PECL or PIE extensions. The slide says 17 PECL extensions were tested against PHP 8.5: 14 behaved identically and 3 lost only the file and line in warnings. Zend extensions such as Xdebug are refused, and there are no streams or sessions. For web work, --web builds a standalone prefork HTTP server binary, and elephc monitor --apm adds profiling and APM.
Generics, and PHP’s own attempt
Elephc accepts native class Box<T> syntax, or @template docblocks, and specialises each use per type argument at build time. Slide 17 benchmarks 3 million iterations: a generic Box<int> and a hand-written int class both took 0.11 s, and an untyped mixed version took 0.21 s.
That sits against PHP’s own history, which slide 8 lays out as a timeline. Runtime generics stalled on type inference in 2024, and a compile-time-only version was floated in 2025 without a proposal. In 2026 the Bound-Erased Generic Types RFC by Seifeddine Gmati was declined, with 7 votes for and 19 against in a vote that ran from 14 to 28 June. A pre-RFC thread on reified generics opened on 6 August. The slide quotes the PHP Foundation as saying that checking generics on live objects is “an order of magnitude harder”. Elephc resolves each generic use before the program runs, which works because it compiles the whole program it sees.
DOOM, and “plain PHP”
Slide 19 is the showpiece: DOOM written in PHP and compiled by Elephc, in its own repository. The README says it runs at 60 FPS, about 2 ms per frame on a desktop x86-64 CPU (the slide shows 2.51 ms), needs only SDL2 at runtime, and was written from public WAD and format descriptions, not DOOM’s source.
The same README carries the fine print. Hot loops have to use specific shapes to stay machine integers. $i += 1 and $i = $i + 1 keep the counter boxed, as do <= comparisons and $n + 1 bounds. $i++ against an int-typed bound does not. An object argument costs about 20 ns per call, ten times an int-only call. That is useful knowledge for anyone writing for the compiler, and it sits awkwardly beside a slide that calls the code plain PHP, untouched. The loop in the benchmark above uses $i += 1.

Where it stands
Slide 18 gives the status at v0.27.9: 20 of 21 language features shipped (eval() is partial), 24 data types, 678 of the 901 functions in the default PHP build (75%), extension export, CLI, web, iOS and C libraries, and the profiler and APM. Its in-flight list is Symfony compiled whole (pull request 2205, with 8 of 8 web responses and 57 of 57 console commands matching PHP), a native debugger (2267), async and parallel (958), WebAssembly with WAMR (420) and Windows x86-64 (446). Planned are multi-file libraries in v0.28 and 1.0 as a stable contract, “not a date”. The slide’s verdict is plain: today it is an extension or a standalone tool, and the whole-framework build is still in review.

The pull requests tell more than the slide. All five in-flight items were opened by Loulier. Pull request 2205, “Closed-world Symfony build (web + console) at php parity”, has 1,064 commits and was created on 1 November, with review requested from Petrucci. The 8 of 8 and 57 of 57 figures are the author’s own verification. The description reports the full suite on macOS aarch64 at 4,157 passed and 83 failed in the library tests, the same as the baseline, and says Laravel work is included but “not verified or claimed”. It also lists known divergences from PHP: a non-numeric string passed to an int parameter becomes 0 where PHP throws a TypeError.
Compatibility on elephc.dev is more modest than “Symfony compiled”. Of the six extensions Symfony requires, five are complete and one, pcre, is at 73%. WordPress needs four, two complete and two partial: pcre at 73% and hash at 48%. The site’s own wording is that frameworks keep running on PHP while their static modules compile to native libraries. The roadmap keeps the 0.x line on PHP parity and backend foundations, puts the include graph and library completion in 0.28, WebAssembly in 0.30, and says 1.0 is not an active planning gate.
The peers
| Project | Approach | What its own docs say |
|---|---|---|
| KPHP (VK) | Compiles a limited PHP subset to C++, then a native binary served by an embedded HTTP server | Open-sourced in late 2020. Claims 3 to 10x over PHP. Says it rarely compiles existing code without errors. No generators or anonymous classes. |
| PeachPie | Roslyn-based PHP compiler for .NET | Describes itself as a work in progress, maintained in spare time. |
| FrankenPHP | Embeds the real PHP interpreter and Caddy, with static builds and an embed mode that packs an app into one binary | 1.14.0 on 21 November made PHP 8.6 the default. Elephc’s extension output targets PHP 8.5, and extensions are built per PHP version. |
| TypePHP (Swoole) | Self-hosting ahead-of-time compiler from PHP to C++17, with binary, extension and library modes | PHP News reported about 8x on its main benchmark (5.034 s to 0.603 s) and a documented list of incompatible features. |
| PHP’s JIT | Tracing JIT inside the interpreter | The baseline in Elephc’s table. |
| Elephc | Static subset to native code, with extension and library output | Contract: no interpreter fallback. Benchmarks are its own. |
The difference that matters is where each one stops. FrankenPHP and static builds keep the interpreter and make it easier to ship, so PHP’s semantics survive intact. KPHP, TypePHP and Elephc give up part of the language for speed and a standalone binary, and the cost shows up as a list of things that won’t compile. Elephc’s distinguishing bet is the extension output, which lets the compiled part live inside an unchanged PHP deployment. It sits closer to the Rust-for-hot-paths pattern than to a rewrite, which is the route Appwrite described when it moved its server from PHP to Rust. The same pull towards native tooling is visible in Pun, a one-binary PHP toolchain, and in the four Rust rewrites of Composer that Sebastian Bergmann questioned.
Trying it, and the CLI change
The install route on elephc.dev is a script and a version manager:
curl -fsSL https://get.elephc.dev | sh
elvm install latest && elvm use latest --global
One trap for anyone following the slides. The changelog on the main branch has a 0.27.10 entry dated 26 November in which elephc build <source-file> becomes the required form, alongside a new elephc check, and old invocations print a migration hint. The slides and elephc.dev still show elephc hello.php. The releases page lists v0.27.9, from 20 November, as the latest tag, and the code in Cargo.toml says 0.27.9, so 0.27.10 is changelog text that isn’t yet a tagged release. Nightly builds are published daily.
A five-point check before putting it near production
1. Profile first. The talk’s own advice is to compile a measured hot path. Time your function, not a loop of $i += 1.
2. Count the boundary copies. Strings and arrays are copied in both directions, so pass small inputs and return small results.
3. Match the PHP version. The extension output targets PHP 8.5, and you need its development SDK.
4. Check the functions you call. 678 of 901 default-build functions is 75%, and pcre sits at 73%.
5. Pin the version. The CLI changed between the talk and the changelog, and the project is on 0.x.
The talk’s last slide asks for the right kind of help: point it at your hot path and report what doesn’t compile, finish Symfony’s last partial, and add docs, examples and benchmarks. That is a fair summary of the project too. It is early, it is open about where it stops, and the claims worth testing are the narrow ones.
Sources: Guillaume Loulier, slides / Elephc repository / Elephc changelog / Elephc roadmap / Pull request 2205 / DOOM in Elephc / PHP RFC, bound-erased generics / KPHP / PeachPie / FrankenPHP / PHP News, TypePHP
Discover more from Sulat AI & Tech News
Subscribe to get the latest posts sent to your email.




