OPcache — Bytecode Caching in the Box
PHP compiles source code to bytecode on every request — unless OPcache is active. Bundled since PHP 5.5 and enabled by default in most distributions, OPcache stores compiled bytecode in shared memory so subsequent requests skip parsing and compilation entirely.
; php.ini — production-ready OPcache settings
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0 ; disable in production, reload to pick up changes
opcache.save_comments=1 ; keep docblocks (needed by some frameworks)
opcache.revalidate_freq=0
No Redis. No Memcached. No build pipeline. OPcache is pure shared memory — the fastest possible cache. Setting validate_timestamps=0 in production means PHP never checks the filesystem for changes, which eliminates the most common I/O bottleneck in high-traffic applications.
// Check cache status at runtime
$status = opcache_get_status();
echo 'Cached scripts: ' . $status['opcache_statistics']['num_cached_scripts'];
echo 'Hit rate: ' . round($status['opcache_statistics']['opcache_hit_rate'], 2) . '%';
// Invalidate a single file after a deploy
opcache_invalidate('/var/www/app/src/Controller/HomeController.php', force: true);
// Or reset everything
opcache_reset();
Combined with JIT, OPcache transforms PHP from an interpreted language into something much closer to a compiled runtime — without changing a single line of application code.
Significance: Zero-Config Performance
OPcache is the single highest-impact PHP configuration change, yet it requires no code changes and no extra infrastructure. Most PHP applications 2–5× their throughput by simply ensuring OPcache is enabled with sane settings.