Making PHP Fast: OPcache, Preloading, JIT and Worker Mode
PHP itself is quick. Most slow PHP applications are slow because of configuration and architecture. These are the settings and choices that make the biggest difference.
Size OPcache for your codebase
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
Big applications such as Magento easily outgrow the defaults. When OPcache fills up, performance drops sharply and silently.
Preload what you always use
Preloading loads framework classes into shared memory when the server starts. For framework-heavy apps it can trim time from every request.
Know when JIT helps
The JIT compiler shines on CPU-heavy work like image processing or number crunching. Most web requests wait on databases and networks instead, so measure before counting on it.
Tune PHP-FPM
pm = static pm.max_children = 32 ; based on RAM / average process size pm.max_requests = 1000
Try worker mode
Application servers such as FrankenPHP, RoadRunner and Swoole keep your app loaded between requests, skipping the start-up cost each time. For Laravel and Symfony APIs this can multiply throughput, but code must not leak state between requests.
Fix the real bottlenecks
- Profile with Blackfire, Tideways or Xdebug
- Remove repeated database queries in loops
- Cache expensive results in Redis
- Push slow work onto queues
Want this done for you? Find out more about our PHP development service.