How would you improve the performance of a slow PHP application?
Measure first — the bottleneck is rarely where people assume. Profile with Blackfire or Xdebug, and check the database's slow query log before touching PHP at all.
Then work through the layers in order of typical payoff:
- The database, almost always first. Fix N+1 queries by eager loading, add the missing index that
EXPLAINreveals, and select only the columns you need rather thanSELECT *. - OPcache. It caches compiled bytecode so PHP does not re-parse every file on every request. Enabling it is often the single largest win, and it is off by default in some configurations.
- Application caching. Redis or Memcached for expensive computations, rendered fragments, and configuration. Have a clear invalidation strategy before you add it.
- Move slow work out of the request. Emails, report generation, image processing, and third-party API calls belong in a queue.
- HTTP-level caching. Correct
Cache-ControlandETagheaders, a CDN for static assets, and gzip or brotli compression. - PHP itself. Upgrading from PHP 7 to 8 is a meaningful free improvement, and preloading and JIT help specific workloads.
Note: Micro-optimisations such as single versus double quotes are noise. Say so — it demonstrates a sense of proportion.





