---
title: "PHP ❤️ Rust: Every Bridge Between Two Worlds"
url: https://www.exakat.io/php-%e2%9d%a4%ef%b8%8f-rust-every-bridge-between-two-worlds/
date: 2026-10-14
modified: 2026-10-14
lang: en
author: "dams"
description: "PHP ❤️ Rust: Every Bridge Between Two Worlds An Elephant and a Crab Walk Into a Bar PHP and Rust have been walking toward each other from across the room..."
categories:
  - "Technology"
tags:
  - "php"
  - "rust"
image: https://www.exakat.io/wp-content/uploads/2026/10/crab.640.jpg
word_count: 1736
---

# PHP ❤️ Rust: Every Bridge Between Two Worlds

# PHP ❤️ Rust: Every Bridge Between Two Worlds

## An Elephant and a Crab Walk Into a Bar

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](https://w3techs.com/technologies/details/pl-php) 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.

## From PHP, Toward Rust

### 1. Zend Extensions: The Classic Highway

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.

| Project | Pitch |
| ------- | ----- |
| **ext-php-rs** | [Bindings over the Zend API](https://github.com/extphprs/ext-php-rs), macros galore. The respectable choice. Its README requires PHP 8.1 or later. |
| **phper**, aka ["PHP Enjoy Rust"](https://phper-framework.github.io/) | "Pure and safe Rust whenever possible." Supports PHP 7.0 to 8.5. Powers the [Apache SkyWalking](https://skywalking.apache.org/) PHP agent, which is a serious résumé. |
| **alef-backend-php** | [A code generator](https://lib.rs/crates/alef-backend-php), not a compiler: from a Rust library it produces ext-php-rs source for a PHP 8.2+ extension, with classes, methods, free functions and serde conversions. It is the PHP backend of alef, a polyglot binding generator (MIT, version 0.17.35, May 2026). |

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.

### 2. FFI: The Drawbridge

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 `unsafe`decision yourself. FFI is the trust fall of interoperability, and it is common in other languages too.

### 3. WebAssembly: The Neutral Embassy

Why talk directly when you can meet in a sandbox? Compile Rust to WASM, execute it inside PHP through a runtime extension:

| Project | Pitch |
| ------- | ----- |
| **veewee/ext-wasm** | The modern take, still experimental: [wasmtime via ext-php-rs](https://github.com/veewee/ext-wasm), component model, WASI preview1/2, Fibers-based async. Runs DOOM, because of course it does. |
| **wasmer-php** | [Wasmer-based](https://github.com/wasmerio/wasmer-php) runtime, sandboxed. Only PHP 8.0 is supported, on Linux and macOS amd64, with no Windows or arm64 support. |
| **php-ext-wasm** | A [fork of wasmer-php](https://github.com/skylei/php-ext-wasm) that runs WASM through Wasmer since v0.2.0 (earlier versions used wasmi), a matryoshka option. |

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.

### 4. PHP to Rust Transpilation: A Moving Walkway

**php-to-rust**, from [LegacyToRustProject](https://github.com/LegacyToRustProject/php-to-rust), 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.

### Rust powered PHP engine: The Holy Bridge

Many people try this: rewrite the PHP engine in Rust. The official engine is heading for PHP 8.6, so these remain interesting experiments.

- [Phargo](https://github.com/ekinertac/Phargo): PHP engine, written from scratch in Rust: it is capable of serving WordPress pages, with a SQLite database.
- [php-rust](https://github.com/francescotinti/php-rust): a rewrite of PHP 8.5 in Rust, including the bytecode, garbage collector and database interfaces. According to its README, it passes 1,748 unit tests, runs WordPress on MySQL, installs Composer packages and produces PHPUnit output identical to PHP's. Doctrine DBAL and Symfony's http-kernel tests pass, though Doctrine ORM still has failures. It is called phpr.
- [rphp](https://github.com/rphp-lang/rphp) (rphp-lang): pre-alpha PHP-compatible engine with its own lexer, parser, bytecode compiler and VM. It does not copy the Zend architecture, and it is not yet a drop-in replacement for PHP.
- [phpl](https://github.com/lineCode/phpl/): PHP interpreter in Rust, in its early stages. It cannot yet execute complete PHP files.

Another rewrite comes from JoliCode. [Writing the PHP Virtual Machine in Rust (with a lot of help from AI)](https://jolicode.com/blog/writing-the-php-virtual-machine-in-rust-with-a-lot-of-help-from-ai), from [Jolicode](https://jolicode.com/) with a [rphp project](https://github.com/jolicode/rphp), 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.

### The Rumored Bridges: more to come!

Word of mouth and a [tweet from Matthieu Napoli](https://x.com/matthieunapoli/status/2109309533558657246) 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](https://x.com/0x15f/status/2109105401631481904), which hits at rewriting the PHP engine with Rust. Still a mysterious endeavour at the moment, but let's keep an eye on it.

### 7. The Mirror: A Rust Compiler Written in PHP

Compiling Rust code to PHP would make little sense, but apparently, compiling Rust code with PHP does.

**[rustc-php](https://github.com/mrconter1/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.

## From Rust, Toward PHP

Rust can also be the source of the PHP code, or the host that runs it.

### php_codegen: Rust Writes the PHP

[php_codegen](https://github.com/php-rust-tools/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.

### Rust as Plugin Host, Process Front, or Async Engine

| Project | Pitch |
| ------- | ----- |
| **php-tokio** | [Use any async Rust library from PHP](https://github.com/danog/php-tokio): an extension that plugs into the Revolt event loop, so it works with amphp, PSL and ReactPHP. Apache-2.0, 357 stars, no releases listed. |
| **Extism** | Rust as a plugin language: compile a plugin to WebAssembly, then call it from a [PHP host](https://packagist.org/packages/extism/extism). PHP and Rust are both on Extism's supported lists. The runtime library must be installed separately, and the Packagist listing I could see was from 2024, so check the current version. |
| **solder** | [A library to build PHP extensions in Rust](https://github.com/killertux/solder), started as a fork of php-rs. Early and unstable; its README says it only works with PHP 7. |
| **php-rpm** | [An experimental process manager](https://github.com/hjr3/php-rpm): Rust's hyper server takes the HTTP requests and runs PHP itself, in place of nginx and PHP-FPM. The repository was archived in January 2018. |

## The Type Checker Will See You Now

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.