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

Profiling & Benchmarking

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

Closest to 'only careful code review or runtime testing' (d7). Absence of profiling is invisible to linters/SAST; Blackfire/Xdebug/Tideways from detection_hints reveal it only when someone actively measures performance. No automated tool flags 'this team optimises by intuition'.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). Per quick_fix, remediation is installing Blackfire/Xdebug profiling on staging and reading the flamegraph — a tooling setup task, not a code change. Slightly more than a one-line patch but well short of a refactor.

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

Closest to 'minimal commitment' (b1), nudged to b2. Profiling is a practice/tooling habit, not a structural choice baked into the codebase; applies_to spans web/cli/queue but imposes no ongoing maintenance tax once the tool is wired up.

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

Closest to 'notable trap most devs eventually learn' (t5). The misconception (microtime() timing is enough) is the canonical wrong belief — developers reliably guess that manual timing equals profiling, and miss that full call graphs expose unexpected hotspots. Also the production-overhead and dev-vs-prod-dataset gotchas listed in common_mistakes.

About DEBT scoring →

Also Known As

PHP profiling application profiling performance profiling

TL;DR

Measuring where a PHP application spends its time and memory to identify the highest-impact optimisation targets.

Explanation

Premature optimisation without profiling is guesswork — 90% of bottlenecks are typically in 10% of the code. PHP profiling tools include Xdebug (call graph, trace, memory profiling), Blackfire.io (production-grade performance management), Tideways, and SPX. Micro-benchmarking uses microtime(true) for targeted comparisons. Profile in a production-like environment — OPcache and real data change performance characteristics significantly. Focus first on I/O (database queries, HTTP requests) before CPU.

Common Misconception

Adding echo microtime() around code sections is sufficient for profiling. Manual timing only measures wall time for known bottlenecks. A profiler (Blackfire, Xdebug with profiling mode) captures the full call graph, revealing unexpected hotspots that manual timing misses entirely.

Why It Matters

Profiling shows you exactly where time is spent — without it, performance optimisation is guesswork. The bottleneck is almost never where you expect it to be, and optimising the wrong thing wastes time while leaving the real problem untouched.

Common Mistakes

  • Profiling in development with a different dataset than production — small datasets hide N+1 and index problems.
  • Optimising based on code inspection rather than profiler output — intuition is wrong more often than not.
  • Running the profiler in production without sampling — full profiling adds 10–100x overhead.
  • Stopping after fixing the first bottleneck — fix one and profile again, the next bottleneck is now exposed.

Code Examples

✗ Vulnerable
// Guessing the bottleneck without profiling:
function slowReport(): array {
    // Developer assumes the DB query is slow
    // Adds caching around DB call
    // Report still slow — actual bottleneck was CSV generation
    // Profile first: Xdebug/Blackfire shows exactly where time is spent
}
✓ Fixed
// Xdebug profiling — generates cachegrind files
; php.ini
xdebug.mode=profile
xdebug.output_dir=/tmp/xdebug
xdebug.profiler_output_name=cachegrind.out.%p
; Trigger on demand: XDEBUG_PROFILE=1 in query string or cookie
; Open output in KCacheGrind (Linux) or QCacheGrind (macOS/Windows)

// In-code micro-benchmark with hrtime (nanosecond precision)
$start = hrtime(true);
expensiveOperation();
$ms = (hrtime(true) - $start) / 1e6;
echo "Took {$ms}ms\n";

// SPX — lightweight always-on profiler for development
// composer require --dev reliforp/php-spx

Added 15 Mar 2026
Edited 22 Mar 2026
Views 65
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 2 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W
No pings yesterday
Perplexity 19 Amazonbot 17 Google 3 Ahrefs 3 Unknown AI 2 ChatGPT 1 Bing 1 Meta AI 1 Scrapy 1
crawler 46 crawler_json 2
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Medium
⚡ Quick Fix
Add Blackfire or Xdebug profiling to your local/staging environment; look for the widest bars in the flamegraph — those are the bottlenecks
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Performance complaint without profiling data; optimising based on intuition not measurement
Auto-detectable: ✓ Yes blackfire xdebug tideways datadog-apm
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: Medium Context: File

✓ schema.org compliant