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

OPcache Preloading (PHP 7.4)

PHP PHP 7.4+ Advanced
debt(d9/e3/b3/t7)
d9 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9). The detection_hints note automated=no and the only code_pattern is the ini directive opcache.preload. There is no tooling that flags when preloading is enabled in a dev environment or when the preload file is stale after Composer updates — both failure modes are silent until a developer notices stale code behavior or missing changes in production/dev.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix describes disabling preloading in dev (single ini change), regenerating the preload file via a Composer command, and restarting FPM. This is a small set of targeted actions within one configuration/deployment concern, not a single-line patch but not a multi-file refactor either — landing at e3.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The applies_to scope is web context only (not CLI/queue), and the burden is confined to deployment and FPM restart procedures. It does not permeate application code broadly — it's a production configuration concern that affects deployment workflow but leaves the rest of the codebase unaffected.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap (contradicts how a similar concept works elsewhere)' (t7). The misconception field directly states the trap: developers assume preloading behaves like normal PHP file loading (pick up changes on next request), but it actually loads code once at FPM start and requires a restart to reflect any changes. This contradicts the standard PHP development workflow and is a serious gotcha that can cause confusing stale-code bugs in development.

About DEBT scoring →

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 43
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 4 pings M 1 ping 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 0 pings T 2 pings F 0 pings S 2 pings S 0 pings M 2 pings T 0 pings W
No pings yet today
PetalBot 1 Google 1
Amazonbot 7 Google 7 Unknown AI 4 Scrapy 4 Perplexity 3 Ahrefs 3 SEMrush 2 ChatGPT 1 Claude 1 Meta AI 1 Majestic 1 PetalBot 1
crawler 31 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