PHP Preloading — Performance Impact
Also Known As
PHP preload performance
opcache preload
preloading PHP files
TL;DR
Quantifying preloading gains: most benefit on large frameworks (5–15%), negligible on tiny apps — how to measure and tune opcache.preload.
Explanation
PHP preloading (7.4+) eliminates per-request file stat, parsing, and compilation for preloaded files. Real-world benchmark data shows: Symfony applications typically gain 5–10% throughput; Laravel 3–8%; small custom apps with few classes see under 2% improvement. The gains scale with: number of class files loaded per request, disk I/O latency (SSDs reduce the baseline making gains smaller), and opcache hit rate (if opcache already caches everything, preloading has minimal additional benefit). Measure with ab or wrk before and after enabling preloading. Key php.ini settings: opcache.preload, opcache.preload_user, opcache.memory_consumption (increase if preloading fills it).
Common Misconception
✗ PHP preloading speeds up every request equally. Preloading eliminates file compilation overhead for preloaded classes. Requests that heavily use preloaded classes benefit most; requests using mostly non-preloaded code see little improvement.
Why It Matters
Preloading compiles framework and library files into shared memory at FPM start — those files require zero compilation per request, reducing cold-start overhead for large codebases.
Common Mistakes
- Preloading files that change between deploys without restarting FPM — stale preloaded code runs indefinitely.
- Not setting opcache.preload_user to a non-root user — FPM refuses to preload as root.
- Preloading the entire vendor/ directory — wastes shared memory on rarely-used packages.
- Not measuring before and after — preloading adds startup time; verify the per-request savings justify it.
Code Examples
✗ Vulnerable
; php.ini — preloading not set up:
; opcache.preload = ; Missing
; opcache.preload_user = ; Missing — required (non-root)
; Correct:
opcache.preload=/var/www/app/preload.php
opcache.preload_user=www-data
; preload.php should require_once all framework/library files
✓ Fixed
; php.ini — preload framework files at FPM startup
opcache.preload=/var/www/app/preload.php
opcache.preload_user=www-data
; preload.php — list files to compile and cache
<?php
$files = glob('/var/www/app/vendor/laravel/framework/src/**/*.php');
foreach ($files as $file) {
require_once $file;
}
// ~7000 files preloaded once at startup, shared across all FPM workers
; Laravel: php artisan optimize compiles routes + config into cached files
; These are also loaded into OPcache and benefit from preloading
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
15 Mar 2026
Edited
22 Mar 2026
Views
14
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 6
Google 2
Unknown AI 2
Perplexity 1
Ahrefs 1
Also referenced
How they use it
crawler 10
crawler_json 1
pre-tracking 1
Related categories
⚡
DEV INTEL
Tools & Severity
🟡 Medium
⚙ Fix effort: Medium
⚡ Quick Fix
Set opcache.preload=/path/to/preload.php and preload your framework's core classes — this moves the compilation cost from per-worker to server startup, reducing FPM worker memory by 5-15MB each
📦 Applies To
PHP 7.4+
web
laravel
symfony
🔗 Prerequisites
🔍 Detection Hints
FPM workers each compiling same framework files; no preload configured; opcache.preload missing in php.ini
Auto-detectable:
✓ Yes
opcache-gui
blackfire
phpinfo
⚠ Related Problems
🤖 AI Agent
Confidence: Medium
False Positives: Low
✓ Auto-fixable
Fix: Low
Context: File