PHP OPcache: Setup and Byte-Code Cache Optimization

PHP · 19.04.2026
PHP OPcache: Setup and Byte-Code Cache Optimization

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
ParameterValueDescription
memory_consumption128–512 MBRAM for byte-code cache
max_accelerated_files4000–100000Max cacheable files
revalidate_freq0 (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
← Back to Knowledge Base Ask Support