PHP › Performance Optimization & OPcache
How does OPcache's file validation and preloading feature work, and what performance benefit does preloading provide beyond standard bytecode caching?
AdvancedAnswer
OPcache's preloading feature, available since PHP 7.4, lets you specify certain PHP files, typically your framework's core classes, to be compiled and loaded into shared memory once when the PHP-FPM master process starts, making those classes permanently available to every worker process for the lifetime of that process without needing to be checked or reloaded on each individual request, providing an additional performance improvement beyond standard OPcache bytecode caching, particularly beneficial for large frameworks with many core classes that are used on virtually every single request.
; php.ini configuration
opcache.preload=/var/www/preload.php
opcache.preload_user=www-dataReal-world example A large Laravel application configures OPcache preloading to load the framework's core classes once when PHP-FPM starts, achieving a further measurable performance improvement beyond what standard OPcache bytecode caching alone was already providing.