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

OPcache

php PHP 5.5+ Intermediate

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