OPcache Preloading (PHP 7.4)
TL;DR
OPcache preloading (PHP 7.4) compiles PHP files into shared memory at server start — eliminating per-request compilation of framework core files for significant performance gains.
Explanation
Configured with opcache.preload = /path/to/preload.php in php.ini. The preload script uses opcache_compile_file() or require to load files into shared memory. All PHP-FPM workers share this preloaded code. Gains: 10–30% performance improvement for frameworks (Symfony, Laravel). Limitation: preloaded code cannot be reloaded without restarting PHP-FPM — not suitable for development. opcache.preload_user specifies the user to run the preload script as. Frameworks generate preload scripts automatically. Ideal for production only.
Common Misconception
✗ Preloading is safe to use in development — it loads code once at FPM start and cannot be updated without restart. Development needs frequent reloads.
Why It Matters
Preloading framework core files eliminates repeated compilation overhead — a meaningful production performance boost at zero cost to correctness.
Common Mistakes
- Enabling preloading in development — must restart FPM for code changes to take effect.
- Not regenerating the preload file after Composer updates.
- Preloading too much — only framework core, not application code.
Code Examples
✗ Vulnerable
# Development with preloading — requires FPM restart on every change:
; opcache.preload=/var/www/vendor/autoload.php
✓ Fixed
# Production php-fpm.conf:
[production]
opcache.preload=/var/www/config/preload.php
opcache.preload_user=www-data
# preload.php:
<?php
require '/var/www/vendor/autoload.php';
opcache_compile_file('/var/www/vendor/symfony/framework-bundle/FrameworkBundle.php');
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
23 Mar 2026
Views
18
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
Amazonbot 7
Unknown AI 4
Perplexity 2
Google 2
ChatGPT 1
Ahrefs 1
Also referenced
How they use it
crawler 13
crawler_json 1
pre-tracking 3
Related categories
⚡
DEV INTEL
Tools & Severity
🔵 Info
⚙ Fix effort: Medium
⚡ Quick Fix
Enable opcache.preload in production only. Use framework-generated preload files (Symfony: composer dump-autoload --optimize). Restart FPM after changes.
📦 Applies To
PHP 7.4+
web
Symfony
Laravel
🔗 Prerequisites
🔍 Detection Hints
opcache.preload
Auto-detectable:
✗ No
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: Medium
Context: File