← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

OPcache Preloading (PHP 7.4)

php PHP 7.4+ Advanced

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');

Added 23 Mar 2026
Views 18
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S
No pings yet today
Amazonbot 7 Unknown AI 4 Perplexity 2 Google 2 ChatGPT 1 Ahrefs 1
crawler 13 crawler_json 1 pre-tracking 3
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

✓ schema.org compliant