Modern PHP Performance: OPcache, JIT, Preloading and FrankenPHP
PHP is faster than its reputation. A few configuration choices and newer runtimes like FrankenPHP can transform PHP performance and response times.
Modern PHP is fast. Most slow PHP applications are slow because of configuration and architecture, not the language. Here are the levers that matter.
1. OPcache, configured properly
opcache.enable=1 opcache.memory_consumption=512 opcache.interned_strings_buffer=32 opcache.max_accelerated_files=100000 opcache.validate_timestamps=0 ; production only, reset on deploy
Large applications like Magento easily exceed the default limits — when OPcache is full, performance quietly collapses.
2. Preloading
Preloading loads framework classes into shared memory at server start. Gains vary, but for framework-heavy apps it can shave noticeable time off every request.
3. JIT: helpful, but not magic
The JIT shines for CPU-heavy work such as image processing or calculations. Typical web requests are I/O bound, so measure before relying on it.
4. Tune PHP-FPM
pm = static pm.max_children = 32 ; based on RAM / average process size pm.max_requests = 1000
5. Consider an application server
FrankenPHP, RoadRunner and Swoole keep your app booted between requests (“worker mode”), skipping the bootstrap cost entirely. For Laravel and Symfony APIs this can multiply throughput. Test carefully — code must not leak state between requests.
6. Fix the real bottlenecks
- Profile with Blackfire, Tideways or Xdebug
- Remove N+1 database queries
- Cache expensive results in Redis
- Move slow work to queues
How to measure PHP performance before tuning
Tuning without measurement is guesswork. Before changing settings, build a clear picture of PHP performance today:
- Profile real requests. A profiler shows exactly which functions, queries and external calls take the time. Often the biggest win is a single slow query or API call.
- Monitor production. Application performance monitoring reveals slow endpoints under real traffic, not just on a developer laptop.
- Load test. Simulate realistic traffic on staging to find the point where response times start to climb.
- Check OPcache health. Make sure the cache is large enough and hit rates are high; the OPcache documentation lists the settings and status functions.
Record a baseline for response time, throughput and memory per request, then change one thing at a time. If you are evaluating an application server such as FrankenPHP, compare it against your tuned PHP-FPM setup rather than a default configuration, so the comparison is fair.
Want a performance audit of your PHP stack? Get in touch.
