alex_petrov24 Jan 2025 02:42

Spent last week benchmarking OPcache configurations on a Laravel 10 app running PHP 8.2. Sharing the settings that made a real difference.

The defaults are conservative. On a prod server with enough RAM, increasing the string buffer and file count limits has a measurable impact.

opcache.memory_consumption=256
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0
opcache.save_comments=1
opcache.enable_file_override=1

validate_timestamps=0 is the big one. On a server where you control deploys, turning off inode checks drops latency on hot paths noticeably.

Replies (7)
petr_sys24 Jan 2025 02:57

validate_timestamps=0 is standard for production but make sure your deploy process does a cache reset. We run php artisan opcache:clear (or the equivalent php -r “opcache_reset();”) as part of the deploy script.

0
ivan_morozov24 Jan 2025 04:49

max_accelerated_files needs to match or exceed the number of PHP files in your project including vendor. Run find . -name "*.php" | wc -l in your project root to get the real number.

0
sergey_web24 Jan 2025 05:25

On Swoole-based setups you do not get request-level OPcache stats because the process does not restart. Use opcache_get_status() periodically to check hit rate. Anything below 90% and your memory_consumption is probably too low.

PHP
<?php
$s = opcache_get_status(false);
if (!$s) {
echo "OPcache is disabled\n";
} else {
$hits = $s['opcache_statistics']['hits'];
$misses = $s['opcache_statistics']['misses'];
$total = $hits + $misses;
$rate = $total > 0 ? round($hits / $total * 100, 2) : 0;
echo "Hit rate: {$rate}%\n";
echo "Used memory: " . round($s['memory_usage']['used_memory'] / 1024 / 1024, 1) . " MB\n";
echo "Cached scripts: " . $s['opcache_statistics']['num_cached_scripts'] . "\n";
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0
nphp24 Jan 2025 06:15

enable_file_override=1 speeds up include_once and require_once calls because they skip the realpath lookup. Recommended for any app with deep vendor trees.

0
katedev24 Jan 2025 07:44

What about opcache.jit? I see it recommended everywhere but on our app it did not change response time at all.

0
alex_petrov24 Jan 2025 08:49

JIT helps CPU-bound code. Web apps doing mostly IO (DB queries, HTTP calls) will see close to zero benefit. JIT shines on numeric processing, image manipulation, parsing loops. For typical Laravel controllers the bottleneck is network IO, not opcode execution.

0
vova24 Jan 2025 09:29

Agreed. We enabled JIT on a data transformation pipeline and saw 30% improvement there. On the API layer, nothing measurable.

0