OPcache

OPcache: what it is, why it matters, and safe deployment considerations.

On this page

What OPcache Does

OPcache caches compiled PHP bytecode in memory. Without it, PHP must parse and compile scripts on every request. With OPcache, requests are faster and CPU usage drops.

Why It Matters in Production

For real traffic, OPcache is not optional. It is one of the biggest performance wins for PHP apps.

Common Settings (Concept)

Exact values depend on server size. The goal is enough memory for your code and fast revalidation during deployments.

opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
opcache.validate_timestamps=1
opcache.revalidate_freq=2

Deployment Consideration

After deploying new code, OPcache may still serve old bytecode until revalidation. Use timestamp validation or explicitly reset OPcache during deploy if needed.

<?php
if (function_exists("opcache_reset")) {
  opcache_reset();
}

Production Tip

Enable OPcache everywhere. Monitor hit rate and memory usage. Prefer safe deploy strategy (atomic symlink deploys) so files do not change mid-request.