PHP and Rust have been walking toward each other from across the room for years. One is the elephant: over thirty years old, used by about 70% of the websites whose server-side language W3Techs can identify, and believes == is a perfectly reasonable thing for two values to do. The other is the crab: young, armored, allergic to nulls, and insists you prove your code is correct before it runs, which frankly sounds like homework.
For a long time, the gap between them was a rift between continents. Crossing it meant writing C glue code by hand, at night, alone, without a debugger. That era is over. What changed is not the languages: it’s the sudden ability to produce a PHP VM in Rust with a lot of help from an AI that has read more C code than any human ever will. The results are wildly uneven, sometimes accidental, and occasionally brilliant. The rift is now being covered with bridges. Some are suspension bridges. Some are rope. One is a DOOM renderer.
This post inventories every crossing point between the two languages, in both directions, with notes on each project’s maturity where the sources show it.
This is the obvious move: write a PHP extension, in Rust instead of C. The Zend API stays the reference: the extension still has to speak its C-level interface. In fact, there are currently several ways to do this, including one that writes the extension code for you.
Async calls in its output run through Tokio block_on, so from PHP’s side they behave synchronously.
These solutions are solid and battle tested. This is the road production code actually takes when it needs Rust speed inside PHP. It is also a great avenue to keep a production monolith in PHP, and offload heavy work to Rust.
Other languages are not so lucky: few have such comfortable tools to merge with PHP.
With FFI, no framework is needed. Since PHP 7.4, you can compile a Rust crate as a cdylib (.so, .dylib, .dll), declare the C signatures with FFI::cdef(), and call it. The elephant extends its trunk; the crab extends a claw; a C header mediates because neither trusts the other’s native language.
This solution is light and fast: so much that there is nothing more to explain than the paragraph above. And you own every unsafedecision yourself. FFI is the trust fall of interoperability, and it is common in other languages too.
Why talk directly when you can meet in a sandbox? Compile Rust to WASM, execute it inside PHP through a runtime extension:
This is the safest way, as a WASM binary can’t touch PHP’s memory. But you pay a toll at each call boundary. veewee’s ext-wasm is experimental, so expect its API to change before 1.0.
php-to-rust, from LegacyToRustProject, is an agent that converts an entire PHP project to Rust, module by module, with a verification loop: the Rust must compile, run, and produce identical output to the original PHP, or the AI fixes it and tries again. WordPress plugins are the first-class target.
It is not a transpiler; it’s a very patient intern with a diff tool. It is in early development, with a handful of commits so far.
Many people try this: rewrite the PHP engine in Rust. The official engine is heading for PHP 8.6, so these remain interesting experiments.
Another rewrite comes from JoliCode. Writing the PHP Virtual Machine in Rust (with a lot of help from AI), from Jolicode with a rphp project, which calls itself a research project, not a production runtime.
Beyond the headline of rewriting PHP engine in Rust, you can follow various ways to do it: some experiments are trying to run subsets of PHP features, others are running it against an ever growing set of tests, whether it be the .phpt or the ones from popular projects. The goal is always the same: identify the parts of PHP that are not possible to run with Rust.
Word of mouth and a tweet from Matthieu Napoli point to compiling Rust on the fly from within a Laravel application. No public artifact to cite yet: if this bridge exists, you’ll have to wait for publication.
And another experiment is coming from tweet from Jake Casto, which hits at rewriting the PHP engine with Rust. Still a mysterious endeavour at the moment, but let’s keep an eye on it.
Compiling Rust code to PHP would make little sense, but apparently, compiling Rust code with PHP does.
rustc-php is a Rust compiler with ownership checking, borrow checking, generics, traits and closures, written in PHP, emitting x86-64 Linux ELF binaries directly, no LLVM, no linker. Its stated use case: “compile Rust on a shared hosting server from 2008 where the only installed runtime is PHP.” It is the perfect comedic twin of the previous category: while Rust developers rewrite PHP in Rust, PHP developers are compiling Rust in PHP. The circle is not just complete; it is smug about it.
Rust can also be the source of the PHP code, or the host that runs it.
php_codegen is a Rust library with a fluent API for writing PHP source code: classes, functions, enums, interfaces, traits, methods and properties. It is not a transpiler: nothing reads Rust code and translates it. You describe PHP code in Rust, and the output is PHP source. The docs.rs page for 0.4.0 reports that none of the crate is documented, so the examples folder is the best entry point. It is dual-licensed MIT or Apache-2.0 and maintained by azjezz.
For all this engineering exuberance, one truth keeps resurfacing in every project above: the two languages’ compatibility has hard limits, and they are philosophical, not technical.
The bridges work. What doesn’t transfer is the soul. PHP’s genius is forgiveness: == means “eh, close enough,” arrays are arrays are dictionaries are lists, and a null is just a value that hasn’t decided yet. Nobody, PHPersonne, as the folklore might say, wants to strictly type their code. We are all willing to do it, as it promises marvels and wonders. Yet, Rust’s non-negotiable entry fee is exactly that strictness: types proven, ownership proven, no hand-waving. To pass into Rust, PHP code must renounce the very flexibility that made it productive; to host PHP, Rust must build a runtime that simulates a looseness it was designed to reject. Every interpreter above has to model PHP’s loose values somehow: a type-juggling layer, and, likely, a quiet apology.
This is why the pragmatic bridges are partial: extract the static, well-typed, hot modules into Rust, via FFI or extensions, and let the rest of the application keep living its dynamic best life on the PHP side. Business rules are often fuzzy, vague, evolving and leaving no time to enforce maximum verification. The elephant does not need to become a crab. It just needs the crab to carry the heavy boxes.
The experiments keep coming; that is important, and healthy. The AI era is taking care of that. The mature engineering question is no longer can PHP and Rust talk, but how much of each other’s personality they should be asked to adopt. On that, both languages would probably agree: none, thank you.
Now excuse me while I push this pull request: it compiles, it passed the tests, and honestly, that’s the only kind of trust fall either of them respects.




