David Buzz's Rust PHP project: an independent re-implementation of PHP in Rust whose goal is
to pass the php-src .phpt test suite, 100%, and have runtime performance as-good-or-better
than the classic C impl. Passing tests: 21,842 of the 21,843 in-scope tests that run
(21,827 pass, 15 expected failures; the one failure, ext/openssl's
stream_server_reneg_limit, failed in the parallel run because it and
stream_server_reneg_limit_trampoline write and delete the same temporary certificate; since
125e811f the runner keeps the two apart, phpt-conflicts.txt, and both pass). Recorded in
22-NOV-2026.full-test-run.log with the build, the Rust tests
and the timing below.
Speed: total runtime 0.49x the C implementation (PHP 8.5.12) on identical inputs, both at
their defaults (perf/bench/timing.py), every input faster.
C PHP 8.5.12 (/usr/bin/php8.5) |
Ours (release build of 725007d4) |
Ratio | |
|---|---|---|---|
| Total wall-clock | 3.330 s | 1.637 s | 0.49× |
| Total CPU (user + system) | 3.319 s | 1.628 s | 0.49× |
The original PHP is written in C. This project ports it to idiomatic, best-practice Rust
(clippy-pedantic clean, unsafe only in audited FFI modules), matching PHP's observable
behaviour byte for byte: error messages, line numbers, var_dump layout, float printing.
Current implementation coverage, test results, and remaining work are tracked in FEATURE_GAP.md.
A Cargo workspace; one crate per concern (engine) or per PHP extension (libraries). The full list with the php-src files each one ports is in CLAUDE.md. The important ones:
| Crate | Role |
|---|---|
php-lexer, php-parser |
tokenizer and PHP 8.x parser/AST |
php-runtime |
zval, zend_string, ordered hash table, operators, type juggling, var_dump/serialize |
php-vm, php-cli |
compiler, executor, classes, exceptions, generators, fibers; the php binary |
phpt-runner |
Rust port of run-tests.php; runs .phpt files and reports pass rates |
php-* (the rest) |
one library per extension, each with its own oracle-driven test suite |
The project builds with the latest stable Rust. These are the steps of the official install page, https://rust-lang.org/tools/install/.
Install (macOS, Linux, or another Unix-like OS):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shUpdate an existing installation to the latest stable:
rustup --version
rustup updateAll tools are installed to the ~/.cargo/bin directory: rustc, cargo and rustup.
rustup tries to add that directory to your PATH during installation. The change may not
take effect until the console is restarted or you log out and in again, and on some systems it
does not succeed at all. If rustc --version fails after installing, this is the most likely
reason.
Versions:
- Minimum: Rust 1.88 (
rust-versioninCargo.toml;cargorefuses to build with an older compiler). - Maximum: none.
- What CI builds with: 1.95.0 in the gating jobs (
.github/matrix.php), and the latest stable in a nightly job of its own (LATEST_STABLE_RUST), so that a compiler change shows up there first. - The x86-64 and AArch64 JIT emits machine code that relies on how the compiler lays out a
PHP value. After changing compiler version, run
cargo test -p php-vm value_layout: if it fails, run withBUZZS_JIT=0and report it.
The extension crates also link system C libraries (libxml2, ICU, libgd, OpenSSL and others);
the package list CI installs on Ubuntu 24.04 is .github/actions/apt-x64/action.yml.
cargo build -p php-cli -p phpt-runner # builds target/debug/php and the runner
target/debug/php -r 'echo 1+2, "\n";' # 3
target/debug/php script.phpRun the php-src suite (or any subdirectory of it) against our binary:
env -u LANGUAGE target/debug/phpt-runner --php target/debug/php -j 8 -q --no-artifacts --summary-depth 2 modules/php-src/tests
target/debug/phpt-runner --php target/debug/php -j 8 -q --no-artifacts modules/php-src/Zend/testsenv -u LANGUAGE matters only if your shell exports LANGUAGE (glibc's gettext lets it override
LC_ALL, which fails six ext/gettext tests under any PHP, including /usr/bin/php8.5). Drop -q to list every test; add --show-diff to see expected-vs-actual for failures.
--json report.json plus scripts/update_feature_gap.py report.json rewrites the % column
of FEATURE_GAP.md from a run. phpt-baseline.txt lists known failures so CI only fails on
regressions (--baseline phpt-baseline.txt, refresh with --update-baseline).
Per-crate checks, as required before any work is declared done:
cargo fmt && cargo clippy --all-targets -p <crate> && cargo test -p <crate>The full run, recorded as evidence in git, is one command:
./run-all-tests.sh # add --no-commit to write the log without committing itIt builds the whole workspace in release mode, runs cargo test --workspace --release, the
full in-scope PHPT suite on the release php (every PASS/FAIL line, a diff for each failure,
checked against phpt-baseline.txt) and perf/bench/timing.py against /usr/bin/php8.5. All of
the output goes to <DD-MON-YYYY>.full-test-run.log in the repository root, ending in a summary
of the four phases, and the script commits that file locally (it never pushes).
The latest is 22-NOV-2026.full-test-run.log; 16-NOV-2026.full-test-run.log is an earlier
run in the same layout, without the timing phase.
Use these incremental dev-profile builds for correctness checks and scoped PHPT
runs. Reserve --release for performance measurements: the release profile uses
thin LTO and one codegen unit, which makes rebuilding test executables expensive.
Keep build directories consistent and avoid cargo clean during edit/test loops.
For multiple affected crates, combine their -p selectors in one command.
The deliverable is one number: run the C implementation and this one side by side on
identical inputs, each with its default configuration, and the total runtime of ours must be
at most 1.10x the total runtime of C. C's CLI default has opcache loaded but disabled
(opcache.enable_cli=0) and no JIT; ours runs with its own trace JIT on (BUZZS_JIT=0 turns
it off).
python3 perf/bench/timing.py # builds the release php if needed, then compares it with /usr/bin/php8.5perf/bench/timing.py builds the release php of the checkout (cargo build --release -p php-cli,
so target/release/php, the binary scripts/acceptance.sh measures too; give a binary as the
argument to measure that one instead), then runs Zend/bench.php, Zend/micro_bench.php, perf/bench/suite/*.php
and the perf/bench/<op>.php loops under both binaries, alternately on the same cores, takes
the fastest of 5 rounds per input and compares the totals. Met (release build of
725007d4 against PHP 8.5.12, 22 Nov 2026, PHASE 4 of 22-NOV-2026.full-test-run.log): ours
1.637 s against C's 3.330 s, 0.49x wall-clock (0.49x CPU time). Every one of the 31 inputs
is faster, from 0.33x (suite/calls.php) to 0.95x (suite/builtins.php).
scripts/acceptance.sh is the per-workload guide: it builds a release binary and counts the
user-space instructions of 82 workloads against the counts recorded for C in
perf/bench/goal.tsv (each may cost at most 1.10x), recorded from /usr/bin/php8.5
(PHP 8.5.12) on 22 Nov 2026. 80 of the 82 are within it with the JIT on; suite:builtins
(1.15x) and zend:hash1 (1.12x) are over, where 8.5 is 9% and 3% cheaper than the 8.3
the earlier goal came from. perf/README.md explains the instruction-count method.
scripts/pgo-build.sh builds the release binaries twice. The first build is instrumented and
runs the benchmarks above and eight php-src test folders (Zend, tests, ext/standard, spl, pcre,
json, date, mbstring), with the JIT on and off; the second build is compiled with the record of
how that code ran, so the compiler lays out and inlines the interpreter for the paths PHP code
takes. The source is the same and so is the behaviour: the whole in-scope php-src suite gives
the same results on these binaries as on the plain build.
rustup component add llvm-tools # once: the compiler's llvm-profdata
scripts/pgo-build.sh # target/release/php, php-cgi and php-fpm, profile-guidedPGO_TRAIN=<command> adds a training step of your own, run with PGO_PHP, PGO_PHP_CGI and
PGO_PHP_FPM set to the instrumented binaries: serving the pages of the application the build
is for is the best training there is.
Measured on 27 Nov 2026 (Rust 1.100.0, 4d54095d) on one page of a large framework
application, in user-space instructions per request: 1,043.4 M with the plain release build,
951.2 M with the repository's training alone (8.8% fewer), 911.7 M with that application's
pages added through PGO_TRAIN (12.6% fewer). CPU cycles, which are what the visitor waits
for, fell by about a sixth in both cases. A later plain cargo build --release builds without
the profile again.
modules/php-src/ is a READ-ONLY copy of https://github.com/php/php-src — the specification
this port is written against, and the source of the .phpt tests. Only the test directories
are kept (tests/, Zend/tests/, ext/**/tests/, sapi/**/tests/: 23,792 .phpt files,
against 237 MB for a full clone), and it is gitignored. Fetch it with
scripts/fetch-phpt-tests.shThe tests are under the PHP License 3.01. The script pins the revision the conformance numbers
are measured against — cb90f9a2377 (php-src master of 22 Nov 2026; until 22 Nov
0c7255dc521 of 2 Nov, against which the numbers below were measured) — because
phpt-baseline.txt and the pass rate are only meaningful for one php-src revision;
scripts/fetch-phpt-tests.sh --verify checks an existing checkout against that pin. Moving to
a newer php-src means editing the pin and re-baselining.
/usr/bin/php8.5 (PHP 8.5.12) is used as an oracle by the library test suites. Where 8.5 and php-src master differ, the port follows master.
buzzs-rust-php-project is a Rust port of php-src, and most of its files are derivative works of php-src C files. The copyright is shared:
Copyright © 2025–2026, David Buzz <davidbuzz@gmail.com>
Copyright © 1999–2026, The PHP Group and Contributors.
Copyright © 1999–2026, Zend Technologies Ltd., a subsidiary company of Perforce Software, Inc.
The individual authors named in each ported C file's header also hold copyright in the Rust port of that file. The repository is distributed under the BSD-3-Clause, the license php-src master uses. See LICENSE.
Some crates are derived from libraries that php-src bundles under other licenses, and those
parts stay under them. libmbfl (php-mbstring) and libbcmath (php-bcmath) are
LGPL-2.1. timelib (php-date) is MIT, lexbor is Apache-2.0, and there are others.
THIRD_PARTY.md lists every component, its copyright holders and the
crates derived from it. The license texts are in LICENSES/. The test tree
under modules/php-src, tools/lcov (GPL-2.0-or-later) and the linked system libraries
keep their own licenses.
If you want to reuse files from this repository, the LICENSE file has a plain-language addendum listing what compliance requires:
- keep every copyright notice, the port's and the upstream ones;
- ship LICENSE, THIRD_PARTY.md and LICENSES/;
- don't use the project's or the authors' names to endorse your product;
- follow the upstream license for any third-party portion.
Projects with a related thesis or implementation:
- francescotinti/php-rust /
phprust.com — a Rust PHP implementation targeting PHP 8.5,
using the mago parser and a HIR-to-bytecode pipeline. Its methodology is very
different from ours: it does not pass the
.phpttest suite and does not target performance or completeness, so the two projects could not interoperate. - jolicode/rphp — AI-assisted experiment (write-up) exploring a Rust PHP VM and copy-on-write request forking.
- Earlier/smaller efforts:
rust-php/php,tagua-vm(archived), various experimental interpreters and parsers (wudi/php-parser,jorgsowa/rust-php-parser); mago is a PHP toolchain (not an engine) in Rust.
This project follows php-src master, organizes extensions as per-extension crates,
and uses .phpt tests and per-workload instruction counts as its compatibility and
performance measures.
Rewrite It In Rust is a Discord server for people re-implementing software in Rust — cleanroom rewrites, AI-assisted coding and crate makers. This project's work fits it well, and its Disboard listing carries the invite: disboard.org/server/1563548271614627963.
Many agents build concurrently on one machine, so .cargo/config.toml caps cargo at 6
jobs, every oracle php invocation passes -d memory_limit=1G, and the php binary caps its
own address space (at the larger of 4 GiB and 75% of RAM plus swap; PHPRUST_MAX_AS_MB
overrides it). See the "Resource limits" section of CLAUDE.md.