OPcache
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
References
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
13 Mar 2026
Edited
22 Mar 2026
Views
35
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
Perplexity 9
Amazonbot 7
Ahrefs 5
Unknown AI 3
SEMrush 2
Majestic 1
Google 1
ChatGPT 1
Also referenced
How they use it
crawler 28
pre-tracking 1
Related categories
⚡
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