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

Opcode Caching

Performance PHP 5.5+ Intermediate
debt(d5/e3/b5/t5)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The detection_hints list opcache-gui, blackfire, and phpinfo — all specialist tools that require deliberate inspection. A disabled or misconfigured OPcache doesn't surface in application logs or cause visible errors; you must actively check phpinfo() output or use a profiling tool like Blackfire to notice the misconfiguration. Default linters won't flag php.ini settings, so d3 is too generous.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix is essentially a php.ini change (enable OPcache, set validate_timestamps=0, tune memory_consumption) plus a deploy hook or restart step. This is slightly more than a one-line patch (e1) because it may touch php.ini, deployment scripts, and require a PHP-FPM restart, but it doesn't span multiple files in application code — it's a localised configuration change.

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

Closest to 'persistent productivity tax' (b5). OPcache configuration applies across both web and CLI contexts and affects every deployment workflow (stale bytecode after deploy is a recurring operational concern). Every developer touching deployments must understand cache invalidation. However, it doesn't reshape application architecture — it's an infrastructure-level setting — so b7 is too strong. It imposes an ongoing operational tax on every deployment and environment setup.

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

Closest to 'notable trap' (t5). The misconception field documents a well-known gotcha: developers assume OPcache only matters for high-traffic sites and skip enabling it. Additionally, validate_timestamps=1 silently halves the benefit, and stale bytecode after deployment serves wrong code — all documented gotchas that most PHP developers eventually learn the hard way. These are non-obvious but documented in PHP community resources, fitting t5.

About DEBT scoring →

Also Known As

opcache opcode cache PHP bytecode cache

TL;DR

Storing precompiled PHP bytecode in memory to skip the parse-and-compile phase on subsequent requests.

Explanation

PHP normally parses and compiles source files on every request. Opcode caching (via OPcache, the standard built-in extension since PHP 5.5) stores the compiled bytecode in shared memory so subsequent requests for the same file skip compilation entirely. This can improve throughput by 50–90% for typical applications. The JIT compiler introduced in PHP 8.0 extends this further by compiling hot bytecode to native machine code. Proper OPcache configuration (adequate memory, file count, and deployment cache-clear strategy) is essential in production.

Common Misconception

OPcache only benefits high-traffic sites. OPcache eliminates PHP file parsing and compilation on every request — a 2-5x speedup on most applications regardless of traffic volume. It should be enabled on every production PHP server as a baseline.

Why It Matters

PHP compiles scripts to opcodes on every request without OPcache — OPcache stores compiled bytecode in shared memory, eliminating repeated parsing and compilation that typically consumes 30-50% of PHP execution time.

Common Mistakes

  • Not enabling OPcache in production — it is often off by default in minimal PHP installs.
  • Setting opcache.validate_timestamps=1 in production — checks file mtimes on every request, negating half the benefit.
  • Not setting opcache.memory_consumption large enough — cache evictions cause repeated recompilation.
  • Deploying new code without restarting PHP-FPM or touching opcache.php — stale bytecode serves old code.

Code Examples

✗ Vulnerable
; php.ini — OPcache disabled or misconfigured:
;opcache.enable=1          ; Commented out — no caching
opcache.memory_consumption=64  ; Too small for large frameworks — use 256+
opcache.validate_timestamps=1  ; File stat on every request in production — set to 0
✓ Fixed
; php.ini — OPcache production settings
opcache.enable=1
opcache.memory_consumption=256     ; MB — size to your codebase
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0      ; disable in production — manual invalidation
opcache.revalidate_freq=0
opcache.save_comments=1            ; needed for PHPDoc-based tools

; After deploy — invalidate stale cache
; opcache_reset(); or restart PHP-FPM
php -r 'opcache_reset();'
; Or per file: opcache_invalidate('/var/www/app/bootstrap.php', true);

Added 15 Mar 2026
Edited 22 Mar 2026
Views 66
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 5 pings S 3 pings S 1 ping M 0 pings T 0 pings W 2 pings T 0 pings F 0 pings S 0 pings S 1 ping M 1 ping T 1 ping W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 2 pings T 0 pings W
No pings yet today
PetalBot 1 Bing 1
Scrapy 9 Perplexity 8 Amazonbot 7 Google 7 Ahrefs 5 Bing 3 Claude 2 PetalBot 2 Unknown AI 1 Meta AI 1 Sogou 1
crawler 42 crawler_json 4
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ Quick Fix
Enable OPcache with validate_timestamps=0 in production (uses inotify or deploy hook to invalidate) — with it enabled your PHP app can serve 5-10x more requests per second
📦 Applies To
PHP 5.5+ web cli
🔗 Prerequisites
🔍 Detection Hints
opcache.enable=0 in production; opcache.validate_timestamps=1 per-request stat() calls; no opcache warm-up after deployment
Auto-detectable: ✓ Yes opcache-gui blackfire phpinfo
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: File


✓ schema.org compliant