What is PHP OPcache
PHP OPcache speeds up PHP execution by storing compiled byte-code in shared memory. Subsequent requests skip parsing and compilation, delivering 2–10x performance gains. OPcache ships with PHP 5.5+ — no separate installation needed.
Check OPcache Status
php -r "echo opcache_get_status() ? 'Enabled' : 'Disabled';"Enable and Configure OPcache
opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.validate_timestamps=1
opcache.jit=1255
opcache.jit_buffer_size=128M| Parameter | Value | Description |
|---|---|---|
memory_consumption | 128–512 MB | RAM for byte-code cache |
max_accelerated_files | 4000–100000 | Max cacheable files |
revalidate_freq | 0 (prod) / 2 (dev) | File change check interval (sec) |
Production tip: Set
validate_timestamps=0 and revalidate_freq=0 for maximum speed. After deploying code, reset cache: php -r "opcache_reset();"Reset OPcache
php -r "opcache_reset();"
sudo systemctl reload php8.2-fpm