PHPStan Turbo: How PHPStan Got 2.5× Faster With a Native Extension
Direct answer: PHPStan Turbo is an optional native C++ extension that makes the PHPStan static analyser about 60% faster on a cold run (roughly 2.5×). It replaces around 350 of PHPStan's internal PHP classes with C++ versions of the same name, and analysis results are identical with or without it. It ships prebuilt with the phpstan/phpstan Composer package for PHP 8.2+, so most projects get it just by upgrading.
If you searched "PHP vs Turbo", you probably saw PHPStan suddenly get much faster and wondered whether Turbo is a new PHP runtime. It isn't. It's a native extension that speeds up one PHP program, PHPStan, and it's one of the cleanest real-world examples of a pattern I covered in my native PHP series: keep PHP as the source of truth and move hot paths to native code. (If you meant Hotwire Turbo, the JavaScript library, that's unrelated.)
What is PHPStan Turbo?#
PHPStan is the most widely used static analyser for PHP, created by Ondřej Mirtes. It reads your code without running it and reports type errors, impossible conditions and dead code. On a large codebase a full run can take a minute or more, which is why speed matters.
Turbo is published as phpstan/turbo. In its own words, it's "a native PHP extension that makes PHPStan about 60% faster on a cold run." It arrived with PHPStan 2.2.6 in July 2026; the big jump came with 2.3.0 in October 2026, and the current release is 2.3.6 (November 15, 2026).
How Turbo works#
The clever part is shadowing. Each native class takes the exact name of a PHP class in PHPStan. When the extension is loaded, PHP uses the C++ class; when it isn't, the original PHP class runs. The PHP version stays the reference implementation, which is why results can be identical.
The speedup was built up in layers. Here's the breakdown from the package page, as a share of the time a run takes without Turbo:
| Layer | Version | Time saved |
|---|---|---|
| Native hot paths | 2.2.6 | 16% |
| Forked workers (fork from the booted process instead of starting fresh) | 2.2.10 | 4% |
| Trusted types (an OPcache optimiser pass that drops redundant type checks in PHPStan's own code) | 2.2.13 | 8% |
| Native analysis engine (~350 classes shadowed) | 2.3.0 | 30% |
| Total | 58% |
Turbo also reimplements php-parser's parsing engine natively, while tokenising stays in PHP. Rules, third-party PHPStan extensions, BetterReflection and phpdoc-parser all stay in PHP, so the parts the community extends are untouched. The package page also says Rector runs about 2× faster with Turbo.
How much faster in practice?#
Independent numbers line up with the claims on cold runs. Sander Muller benchmarked PHPStan on WordPress at level 9 (Apple M4 Pro, PHP 8.5):
| Run | PHPStan 2.1.49 | PHPStan 2.3.1, no Turbo | PHPStan 2.3.1, Turbo |
|---|---|---|---|
| Cold (no cache) | 48.6 s | 31.2 s | 13.3 s |
He also makes an important point in a post titled "Nobody runs PHPStan cold": day to day, PHPStan uses its result cache, and an average commit took 1.8 seconds on 2.3.1. So Turbo matters most in CI without a warm cache, on first runs after dependency updates, and on big monorepos. On your laptop the cache was already doing most of the work.
How to get it#
Most people don't need to do anything:
- Composer users:
phpstan/phpstanincludes prebuilt binaries for Linux (glibc and musl, x86_64 and arm64), macOS arm64 and Windows x86_64, for PHP 8.2 and newer. - Downloaded
phpstan.pharusers: install the extension with PIE:pie install phpstan/turbo. - Check it's active:
vendor/bin/phpstan diagnose.
Turbo is version-gated: it only activates when its version matches the one the PHPStan release expects. Otherwise PHPStan prints a note and runs without it. A mismatched extension can only cost speed, never change results. There's no switch to turn it off.
The quickest win for most teams: cache PHPStan's result cache directory between CI runs, then upgrade to get Turbo for the cold runs that remain.
What Turbo teaches about native PHP#
Turbo is a useful counterpoint to the PHP compilers in this series. elephc and TypePHP try to compile PHP automatically. Turbo hand-writes the hot parts in C++ and keeps PHP as the specification. It's more work, but it's shipping to everyone today, and the design choices are worth copying for any performance-critical PHP library:
- Profile first. The layers in the table target where time actually went.
- Keep a reference implementation. The PHP classes define correct behaviour; native code must match them.
- Make it optional and safe to be missing. Version gating means a broken or absent extension falls back to PHP.
- Leave the extension points alone. Rules and plugins stay in PHP, so the ecosystem doesn't break.
It's also a nice answer to "is PHP too slow for serious tools?" The answer here was to keep PHP for most of the code and go native only where profiling said it would pay.
Frequently asked questions#
Is PHP Turbo a new PHP runtime?#
No. Turbo here is PHPStan Turbo, a native extension that speeds up the PHPStan static analyser. It does not change how your application runs. Hotwire Turbo, the JavaScript library, is unrelated.
Does PHPStan Turbo change analysis results?#
No. Results are identical with or without it. The native classes mirror PHPStan's PHP classes, which remain the reference implementation, and the extension only activates when its version matches the PHPStan release.
How do I enable PHPStan Turbo?#
If you install phpstan/phpstan with Composer on PHP 8.2 or newer, prebuilt binaries are included. If you use a downloaded phpstan.phar, run pie install phpstan/turbo. Check with vendor/bin/phpstan diagnose.
How much faster is PHPStan with Turbo?#
About 60% less time on a cold run, roughly 2.5x. One independent WordPress benchmark went from 31.2 seconds to 13.3 seconds. Warm runs using the result cache gain less.
Key takeaways#
- PHPStan Turbo is a native C++ extension that makes PHPStan about 60% faster on cold runs, with identical results.
- It shadows around 350 PHP classes with same-named native classes; the PHP code remains the reference implementation.
- It ships prebuilt with
phpstan/phpstanfor PHP 8.2+; phar users install it with PIE. - The biggest gains are in CI and cold runs. Warm runs already benefit from the result cache.
- It's a model for native PHP done safely: profile, keep a reference, make native optional.
Sources#
- phpstan/turbo on Packagist (description, breakdown, install, version history)
- Sander Muller: Nobody runs PHPStan cold
- PHPStan
Want faster CI for a PHP codebase? Get in touch.