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

Opcode Optimisation

Compiler PHP 5.5+ Advanced
debt(d5/e1/b3/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, vld, and blackfire — all specialist tools requiring deliberate setup. A developer won't know OPcache is misconfigured or that optimization_level is suboptimal without querying phpinfo(), using opcache-gui, or profiling with blackfire. No default linter flags this; it requires intentional inspection.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix is explicit: set opcache.optimization_level=0x7FFFBFFF in php.ini — a single configuration line. Removing manually pre-computed constants is equally a local one-line change per occurrence.

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

Closest to 'localised tax' (b3). The concern is scoped to PHP runtime configuration and PHP files that misuse manual micro-optimisations. Once OPcache is correctly configured, no ongoing burden exists. It applies to web and cli contexts but doesn't reshape architecture or slow down multiple workstreams once addressed.

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

Closest to 'notable trap' (t5). The misconception field explicitly states that developers believe manual pre-computation of constants (e.g. 60*60*24) improves performance, when OPcache's constant folding already handles this at compile time. This is a documented, well-known PHP gotcha that most developers learn after profiling — it contradicts intuition but is not catastrophic, placing it firmly at t5.

About DEBT scoring →

Also Known As

opcache optimizer constant folding dead code elimination PHP optimizer

TL;DR

PHP's compiler applies optimisation passes to the opcode array before caching — constant folding, dead code elimination, and pass-through minimisation reduce instruction count.

Explanation

PHP's Optimizer (part of OPcache) applies multiple optimisation passes to compiled opcodes: constant folding (2 + 3 compiled to 5), dead code elimination (if (false) { } removed), array/string merging (concatenated literals merged), pass-through optimisation (unnecessary RETURN opcodes removed), and live variable analysis (unused variables eliminated). PHP 7+ uses type inference during optimisation, enabling more aggressive dead code elimination with typed code. These optimisations happen once at compile time and are cached — they have zero runtime overhead once in OPcache.

Common Misconception

Manual micro-optimisations like pre-computing constants improve PHP performance — OPcache's constant folding computes 60 * 60 * 24 at compile time; manual pre-computation adds clutter with zero performance benefit.

Why It Matters

Understanding OPcache optimisations explains why premature micro-optimisations are pointless in PHP (the compiler already does them) and where real performance gains come from (I/O, algorithms, caching).

Common Mistakes

  • Pre-computing constants manually — PHP optimiser does this at compile time.
  • Avoiding clear code for micro-optimisation — the optimiser handles constant expressions.
  • Not enabling OPcache — without it, no optimisations apply on any request.
  • Thinking opcache.optimization_level controls all passes — different passes have different levels.

Code Examples

✗ Vulnerable
// Unnecessary manual micro-optimisation:
$secsPerDay    = 86400;          // Pre-computed manually
$secsPerWeek   = 604800;         // Clutter — compiler does this
$bytesPerMB    = 1048576;

// Complicated null check to avoid function call:
if (isset($arr['key']) && $arr['key'] !== null) { }  // Premature
✓ Fixed
// Let the compiler optimise:
$secsPerDay  = 60 * 60 * 24;     // Compiler folds to 86400
$secsPerWeek = 60 * 60 * 24 * 7; // Compiler folds to 604800
$bytesPerMB  = 1024 * 1024;       // Compiler folds to 1048576

// Readable null check:
if (isset($arr['key'])) { }  // Clear intent, same performance

// View opcache stats:
$status = opcache_get_status();
// Check: ['opcache_statistics']['hits'] vs ['misses']
// High miss rate = too many files or opcache.max_accelerated_files too low

Added 16 Mar 2026
Edited 22 Mar 2026
Views 61
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 2 pings W 1 ping T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 1 ping T 2 pings F 1 ping S 1 ping S 4 pings M 1 ping T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S 2 pings S 0 pings M 1 ping T 0 pings W
No pings yet today
Google 1
Google 9 Scrapy 8 Amazonbot 7 Perplexity 7 Ahrefs 4 SEMrush 4 Unknown AI 2 Claude 2 ChatGPT 2 Bing 1 Meta AI 1 Majestic 1
crawler 42 crawler_json 6
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Enable OPcache with opcache.optimization_level=0x7FFFBFFF (all optimisations) — the optimiser eliminates dead code, constant folds, and simplifies expressions before caching
📦 Applies To
PHP 5.5+ web cli
🔗 Prerequisites
🔍 Detection Hints
OPcache enabled but optimization_level not set; dead code in PHP not removed at compile time; constant expressions computed at runtime
Auto-detectable: ✓ Yes opcache-gui vld blackfire
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Medium ✓ Auto-fixable Fix: Low Context: File


✓ schema.org compliant