Preloading compiles and links classes into shared memory at startup, and the linking is what makes it different from opcache.
// opcache.preload=/app/preload.php
// opcache.preload_user=www-data
$files = (new SymfonyComponentFinderFinder())
->files()->in(__DIR__ . '/vendor/laravel/framework/src')
->name('*.php');
foreach ($files as $file) {
opcache_compile_file($file->getRealPath());
}
// preloaded classes cannot be changed without a restart.
The measured gain on a typical framework application is smaller than the announcements suggested — often five to ten per cent — and the operational cost is that every deploy needs a full restart rather than a reload. Classes with unresolvable parents are skipped with a warning at startup, so the preload script has to be ordered or it silently preloads less than intended. Checking opcache_get_status() for the actual count is the only way to know it worked.