Oxidize 0.1.0 — experimental, open source (MIT/Apache-2.0)
Rewriting a PHP application in Rust is a big-bang project, and big-bang
rewrites rarely ship. But most Symfony apps don't need a rewrite: they have a
handful of hot or heavy paths — a report that crunches 200k rows, an XLSX
export that eats 350 MB, an endpoint that gets hammered — and a lot of code
that is fine as it is.
Oxidize lets you move exactly those
paths to Rust, inside the app you already have, and keep going for as long as
it pays off: the strangler-fig pattern, applied to a PHP application.
PHP app ──▶ PHP + Rust (mode A) ──▶ Rust + PHP (mode B) ──▶ Rust Mode A: Rust inside Symfony
A PHP extension (built with ext-php-rs) plus a Symfony bundle. Your Rust code
becomes routes, services, Messenger handlers, listeners and console commands
that Symfony routes, secures and profiles like its own:
#[route("/api/report/{id}", methods = ["GET"], name = "report")] #[is_granted("ROLE_USER")] fn report(id: u32, ctx: &Ctx) -> Result<Json<Report>, HttpError> { let repo: SaleRepositoryProxy = ctx.get()?; // an existing PHP service, typed Ok(Json(aggregate(&repo.find_for_report(id)?))) } Rust can call your existing PHP services and read the session, the user, the
cache, Twig, Doctrine's connection (in the same transaction). PHP can call
Rust services and functions. Nothing else in the app changes: debug:router
lists the Rust routes, the web profiler gets a panel showing every PHP ↔ Rust
crossing.
Mode B: a Rust server in front, PHP as the fallback
When enough of the app is Rust, flip it around: a native Rust server answers
the Rust routes itself and proxies everything else to php-fpm (or to PHP
embedded in-process). A native request can hold one Symfony request open, so
its PHP calls still share the session, the user and the Doctrine transaction.
Symfony's access_control rules are exported to the server and enforced for
native routes too.
Numbers (one machine, re-measured at 0.1.0)
| PHP | Rust | |
|---|---|---|
| Stats over 200k rows, mode A | 72 req/s | 460 req/s (6.4×) |
| CSV report, 1M rows | 2.2 s | 0.25 s |
| XLSX export, 100k rows | ~8 s, 351 MB | 0.37 s |
| Hello JSON, native route in mode B vs a Symfony request | ~1.3k req/s | ~27k req/s |
| Handler making 7 PHP calls in mode B | 21.7 ms per-call | 4.9 ms in one request scope |
And where it does not help — this matters more than the wins:
- A trivial route in mode A is not faster: the request still boots Symfony (1306 vs 1241 req/s, within noise).
- A DB-bound endpoint gains nothing until the query gets better. In the case study below, one SQLite pragma made PHP's search 2.7× faster — more than any Rust variant.
- A page rendered by Twig gains only what the query gains: rendering is still PHP, and putting the Rust server in front doesn't speed it up further.
A real app: the Symfony Demo
Benchmarks of hello-world routes prove little, so I ported four endpoints of
the official Symfony Demo application (search JSON, RSS, the paginated post
list rendered by Twig, and an admin page behind access_control) and wrote
parity tests: the PHP route and the Rust route must give equivalent responses
in mode A and mode B, including login, CSRF, flash messages and access control
across PHP and native routes.
All 85 parity checks pass. With the same SQLite tuning on both sides
(measured on a busy machine, so read the ratios, not the absolute numbers):
| endpoint | PHP | Rust, mode A | Rust, mode B (Doctrine) | Rust, mode B (native reads) |
|---|---|---|---|---|
| RSS feed | 107 req/s | 145 (1.4×) | 353 (3.3×) | 923 (8.6×) |
| search (JSON) | 393 req/s | 369 (no gain) | 401 (1.0×) | 1220 (3.1×) |
| post list (Twig) | 104 req/s | 195 (1.9×) | 160 (1.5×) | 173 (1.7×) |
The search is the honest one: in mode A it gains nothing, because the request
still boots Symfony and runs the same SQL; it only pays off once PHP leaves
the request path (mode B with native reads). The Twig page gains from the
faster query, but rendering stays in PHP, so mode B can't take it further.
The case study also found five bugs in Oxidize itself (one silently disabled
a mode B optimisation, one could let a shared cache store a logged-in user's
page). All five are fixed in 0.1.0, each with a test. Full write-up, with
methodology and the parts that didn't work:
the case study.
The boring parts that make it usable
- One command to build your extension: a builder image for PHP 8.2–8.4 (NTS, ZTS, Debian, Alpine), a Dockerfile stage for production php-fpm images, and a GitHub Action.
- Safety at the boundary: PHP arrays are read in place without copying; a PHP fatal error or
exit()under Rust frames unwinds the Rust frames (destructors run) and then reaches PHP unchanged; the conversion code and the server's parsers are fuzzed. - Security in mode B: two independent security reviews, every finding fixed with a test that tries the attack.
- Operations: health and Prometheus metrics on a separate admin port, structured logs with request ids passed to Symfony, graceful shutdown, and a protocol handshake that refuses a bundle and a server from different releases.
- Tested on PHP 8.2, 8.3, 8.4; Linux and macOS; php-fpm, FrankenPHP, Swoole, RoadRunner and embedded PHP.
Weld
The repository also ships Weld: Symfony's dependency-injection container
recreated for Rust and compiled at build time (autowiring, tags, tagged
iterators and locators, decorators, expressions, bundles, autowiring by
generic arguments), plus a Doctrine-compatible ORM and a Messenger that
shares queues with PHP. It is what the Rust side of a migration can grow into.
Status
Experimental. Nobody runs it in production yet, it is not on Packagist or
crates.io yet, and I would love to hear what breaks when you try it on a real
app. Start here:
Getting started.
