elephc vs TypePHP: Which PHP AOT Compiler Should You Bet On?
Direct answer: elephc and TypePHP both compile PHP ahead of time to native code, but they take opposite routes. elephc (Rust, MIT) emits assembly directly and drops the Zend Engine entirely. TypePHP (Swoole, GPL-3.0) translates PHP to C++ and keeps a bridge to the Zend runtime. Pick elephc for small standalone binaries and PHP extensions; pick TypePHP if you live in the Swoole world and want closer compatibility with existing PHP. Neither is production-ready for a full framework app as of November 2026.
Two serious PHP AOT compilers showed up within months of each other in 2026, after years of "PHP can't be compiled" being accepted wisdom (HHVM's story aside). If you're choosing which one to experiment with, the useful question isn't "which is faster". It's "which design fits the code I actually have". I've already written up what elephc is and what TypePHP means for PHP performance; this post puts them side by side.
What does an AOT compiler for PHP do?#
An ahead-of-time (AOT) compiler turns PHP source into machine code before the program runs. Normal PHP compiles your script to opcodes at runtime and runs them in the Zend Engine's virtual machine; OPcache caches the opcodes, and the JIT (since PHP 8.0) compiles some hot ones to machine code while the program runs. AOT moves all of that to build time, which only works when the compiler can figure out your types in advance. That's why both projects target a subset of PHP.
elephc vs TypePHP side by side#
| elephc | TypePHP | |
|---|---|---|
| Maintainer | Illegal Studio (Vincenzo Petrucci) | Swoole team |
| Compiler written in | Rust | PHP (self-hosting: it compiles itself) |
| Pipeline | PHP → assembly → as/ld | PHP → C++17 → GCC/Clang |
| Zend Engine at runtime | No. Small custom runtime | Links against libphp through the PHPX bridge for dynamic values and internal functions |
| Outputs | Executables, .so PHP extensions, shared and static libs, iOS libs | Executables, PHP extensions, shared libs, WASI components |
| Platforms | macOS ARM64, Linux ARM64/x86_64; iOS libraries | Linux x64 primary; Windows, macOS, ARM64, Android, iOS, WASI backends depending on toolchain |
| Build requirements | System assembler and linker | PHP 8.4–8.5 CLI + headers, libphp embed library, C++17 compiler, CMake 3.24+, Composer 2, GMP, MPFR |
| Licence | MIT | GPL-3.0 |
| Status (Nov 2026) | v0.27.8, near-daily nightlies | "Under active development", ~2,000 commits; a May 2026 roadmap targets general availability in May 2027 |
The design difference that matters#
elephc removes the runtime; TypePHP replaces the interpreter but keeps the runtime. Almost every practical difference follows from that.
Because elephc has no Zend Engine, its binaries are self-contained and it can target places PHP doesn't normally go, like an iOS static library. The cost: every PHP function you call has to be reimplemented by the elephc team. That's why it publishes coverage numbers (74% of a default PHP 8.5 build's functions as of v0.27.8) and why unsupported behaviour is a compile error.
TypePHP's approach, as Albert Chen put it in a May 2026 talk on Swoole's AOT compiler, "throws out the opcode handler — not the runtime — and links straight against libphp.so." PHPX, a header-only C++ library mirroring PHP's standard library, sits between your compiled code and Zend. You inherit PHP's real behaviour for the dynamic parts, and your build depends on a matching PHP installation.
How strict do you have to be?#
Both want typed, predictable code, but they enforce it differently.
TypePHP's documented restrictions include: the global scope is declaration-only (code goes in functions, with a strict main() for binaries); inferred int, float and bool values use fixed native storage and can't later change type; PHP-compatible integer overflow needs use varint_types; and some highly dynamic reference, closure and reflection patterns aren't supported. The May 2026 talk also listed no $$name or extract(), no yield generators, and strict function arity.
elephc infers types and supports more of the language surface than you'd guess, including generators, Fibers, traits and references. Its limit shows up in the standard library and in dynamic behaviour it can't resolve at compile time.
If your code already passes PHPStan at a high level with real types everywhere (see how PHP's type system got here), you're in good shape for either.
What about speed?#
The only numbers available are the projects' own, so treat them as directional. TypePHP's README reports bench.php dropping from 5.034 s interpreted to 0.603 s compiled at -O3 (about 8×), and micro_bench.php from 13.045 s to 2.021 s (about 6.5×). In his talk, Albert Chen showed a recursive fib(40) going from about 14.8 s to 0.11 s. elephc publishes no headline benchmark; its showcase is DOOM running at the game's native 35 tics per second.
Two cautions. These are CPU-bound micro-benchmarks, and a typical web request spends most of its time waiting on a database. And I haven't seen an independent, like-for-like benchmark of the two compilers. If you run one, publish your scripts.
Which should you choose?#
A short decision list:
- Writing a PHP extension instead of C? Either works. elephc has the lighter toolchain; TypePHP is closer to real PHP semantics.
- Need a self-contained binary with no PHP install on the target? elephc.
- Targeting iOS? elephc's iOS static libraries are the clearer path today.
- Already running Swoole, Hypervel or Workerman? TypePHP. The Swoole team built it for that world, and the talk reports Workerman compiling to a single binary "with only minor patches".
- Shipping closed-source commercial software? Read the licences. GPL-3.0 (TypePHP) and MIT (elephc) have very different obligations if you distribute the compiler or linked runtime.
- Want to compile your whole Laravel app? Neither, yet. Use Octane or FrankenPHP and compile only a hot module.
My own lean, for what it's worth: I'd use elephc to learn and to build tools, and watch TypePHP for server workloads, because keeping the Zend runtime is the more realistic route to compiling real-world code eventually.
Frequently asked questions#
Which is faster, elephc or TypePHP?#
There is no independent like-for-like benchmark yet. TypePHP's README reports roughly 6.5x to 8x speedups on its own benchmark scripts, and elephc publishes no headline benchmark. Both target CPU-bound code, not database-bound web requests.
Does TypePHP need PHP installed?#
To build, yes: it needs a PHP 8.4 or 8.5 CLI with development headers and a matching libphp embed library, because compiled code links against the Zend runtime through PHPX. elephc only needs a system assembler and linker.
Can either compile a Laravel app?#
Not as of November 2026. Both compile a typed subset of PHP. The practical approach is to keep the framework on regular PHP and compile isolated hot paths as extensions or libraries.
What licences do elephc and TypePHP use?#
elephc is MIT licensed. TypePHP is GPL-3.0. Check the obligations before distributing compiled closed-source software.
Key takeaways#
- Both are PHP ahead-of-time compilers for a typed subset; neither compiles a full Laravel or Symfony app today.
- elephc (Rust, MIT) emits assembly with no Zend Engine: self-contained binaries, PHP extensions and iOS libraries.
- TypePHP (Swoole, GPL-3.0, written in PHP) goes through C++ and links against libphp via PHPX, trading self-containment for compatibility.
- Published speedups (6.5×–8× on the README's benchmark scripts) are the vendors' own CPU-bound numbers, not web-app results.
- Choose on design fit and licence, and compile isolated hot paths rather than whole applications.
Sources#
- illegalstudio/elephc on GitHub and elephc.dev
- swoole/typephp on GitHub (README, restrictions, benchmarks)
- Laravel News: TypePHP compiles PHP to native binaries (Eric L. Barnes, Aug 26, 2026)
- Albert Chen: Introduction to Swoole's AOT compiler (slides, May 24, 2026)
Weighing a compiler for a real workload? Get in touch.