Tune PHP OPcache on NetBSD 10
OPcache stores compiled PHP scripts in shared memory, dramatically improving performance.
Configuration file: /etc/php.d/opcache.ini
[opcache]
opcache.enable=1
opcache.enable_cli=0
; Memory allocated for cached bytecode (MB)
opcache.memory_consumption=256
; Number of strings that can be interned
opcache.interned_strings_buffer=16
; Max number of files to cache
opcache.max_accelerated_files=20000
; Revalidation interval (seconds); set 0 in development
opcache.revalidate_freq=60
; Don't validate timestamps in production for max speed
opcache.validate_timestamps=1
; Enable JIT (PHP 8.x)
opcache.jit=tracing
opcache.jit_buffer_size=128M
Reload PHP-FPM
systemctl reload php-fpm 2>/dev/null || rc-service php-fpm reload
Verify OPcache is active
php -r "var_dump(opcache_get_status());" 2>/dev/null | head -20
Or create a small test script:
<?php
$s = opcache_get_status(false);
echo 'OPcache enabled: ', $s['opcache_enabled'] ? 'YES' : 'NO', PHP_EOL;
echo 'Memory used: ', round($s['memory_usage']['used_memory'] / 1024 / 1024, 2), ' MB', PHP_EOL;