Skip to content
AgileLogics
4 min read

Performance Optimization & OPcache

Prerequisites: The PHP lifecycle & PHP-FPM

OPcache caches compiled bytecode in memory, skipping re-parsing the same PHP source file on every single request — one of the single biggest, free performance wins for any production PHP app.

; php.ini
opcache.enable=1
opcache.memory_consumption=128

Beyond OPcache, common high-value fixes once a real bottleneck is profiled (with Xdebug's profiler or Blackfire):

  • Avoiding an N+1 query problem (one query per row in a loop instead of one batched query) — the same issue flagged for Java/C#.
  • Caching expensive, repeated computations (an API response, a rendered template fragment) in Redis or Memcached.

Common mistakes

  • Running production without OPcache enabled — this alone can be a several-times slowdown, and is easy to forget in a manual server setup (frameworks and most hosting providers enable it by default).