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

OPcache

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

Closest to 'only careful code review or runtime testing' (d7). The term's detection_hints list phpinfo, opcache-gui, and blackfire — these are specialist tools a developer must deliberately invoke. A disabled or misconfigured OPcache (e.g. validate_timestamps=1, low memory_consumption) produces no error or warning; the site works correctly but is silently slow, and the problem only surfaces when someone profiles or inspects phpinfo. It does not score d9 because the tools are readily available and the pattern (opcache.enable=0 in php.ini) is concrete.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix is a small set of php.ini directives: enable=1, memory_consumption=256, max_accelerated_files=20000, validate_timestamps=0. This is more than a single-line patch (multiple settings, plus a PHP-FPM restart and deployment procedure awareness) but well short of a multi-file refactor. Scores e3 rather than e1 because the common_mistakes reveal several interacting settings and an operational step (restart FPM) that must be coordinated.

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

Closest to 'persistent productivity tax' (b5). OPcache is a server-level configuration choice that applies to both web and CLI contexts across the entire PHP runtime. Misconfiguration (stale bytecode after deploys, eviction under memory pressure, timestamp validation in production) imposes an ongoing operational tax: every deployment must account for cache invalidation, memory sizing must be revisited as the codebase grows, and CLI scripts may behave differently if opcache.enable_cli is not set. It doesn't reach b7 because it doesn't shape code structure, only operational/deployment practice.

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

Closest to 'notable trap' (t5). The canonical misconception — that OPcache is only for high-traffic sites — is a documented gotcha that causes developers to leave it disabled in production. A second well-known trap is validate_timestamps=1 silently defeating the cache, and a third is forgetting to restart PHP-FPM after deploy so stale bytecode serves old code. These are all documented, eventually-learned gotchas rather than behaviour that contradicts similar concepts in other ecosystems, placing this squarely at t5.

About DEBT scoring →

Also Known As

PHP OPcache opcode cache Zend OPcache

TL;DR

A PHP extension that caches precompiled bytecode in shared memory, eliminating repeated parsing and compilation overhead.

Explanation

OPcache (bundled since PHP 5.5) stores compiled PHP bytecode in shared memory so subsequent requests skip the parse-and-compile phase. It can reduce CPU usage by 50–90% for busy applications. Key configuration settings include opcache.memory_consumption (typically 128–256 MB), opcache.max_accelerated_files (set above your file count), opcache.validate_timestamps (disable in production for maximum speed; invalidate cache on deploy), and opcache.jit_buffer_size (PHP 8.0+ JIT). Misconfigured OPcache can expose cached files to other processes — ensure opcache.restrict_api is set appropriately.

Common Misconception

OPcache is only useful on high-traffic production servers. OPcache eliminates repeated parsing and compilation of PHP files on every request — it provides significant speedup even on low-traffic sites and should be enabled in any production environment.

Why It Matters

Without OPcache, PHP parses and compiles every file on every request — on a busy server this wastes hundreds of milliseconds per request and burns CPU. OPcache cuts PHP execution time by 50–80% with zero code changes.

Common Mistakes

  • Leaving OPcache disabled in production because it was absent from the default php.ini.
  • Setting opcache.validate_timestamps=1 in production — defeats caching by checking file mtimes on every request.
  • Forgetting to restart PHP-FPM after deploying — stale bytecode serves old code until the cache expires.
  • Setting opcache.memory_consumption too low — cache eviction under memory pressure causes random misses.

Code Examples

✗ Vulnerable
; php.ini — OPcache not configured, effectively disabled
; opcache.enable=0
✓ Fixed
; php.ini production settings
opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0  ; clear cache on deploy instead

Added 13 Mar 2026
Edited 22 Mar 2026
Views 94
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 1 ping F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W 2 pings T 5 pings F 6 pings S 10 pings S 8 pings M 1 ping 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 0 pings T 0 pings F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Scrapy 29 Perplexity 10 Ahrefs 8 Amazonbot 7 SEMrush 4 Unknown AI 3 Google 3 Majestic 2 ChatGPT 2 Claude 2 Bing 2 Meta AI 1 PetalBot 1
crawler 71 crawler_json 2 pre-tracking 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ Quick Fix
Enable OPcache with opcache.enable=1, opcache.memory_consumption=256, opcache.max_accelerated_files=20000, opcache.validate_timestamps=0 in production
📦 Applies To
PHP 5.5+ web cli
🔗 Prerequisites
🔍 Detection Hints
opcache.enable=0 in php.ini; opcache not loaded in phpinfo(); high parse time in profiler
Auto-detectable: ✓ Yes phpinfo opcache-gui blackfire
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: File


✓ schema.org compliant