XHProf

A hierarchical function-level profiler for PHP with a lightweight call-graph UI.

Tool
Composer
35stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
26/100Needs Attention
Development Activity0
Maintenance0
Community32
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
65/100Good
Architecture70
Code Quality62
Innovation68
Learning Curve60

XHProf is a hierarchical profiler for PHP originally developed at Facebook, packaged here by lox with a composer.json so it installs cleanly from Packagist. It instruments your code at the function-call level to capture wall-clock time, CPU time, memory usage, and call counts, then aggregates those samples into a parent/child call graph.

The bundled HTML report and Graphviz-based call-graph viewer let you drill into which functions dominate a request, spot expensive call paths, and compare two runs to measure the impact of an optimization. Its low overhead makes it practical to run against real workloads rather than synthetic microbenchmarks.

What You Get

  • A low-overhead C extension that records per-function timing, memory, and call-count data
  • A pluggable run-storage layer (iXHProfRuns) with a filesystem default implementation
  • An HTML report UI with sortable function tables and diff-between-runs support
  • A Graphviz-powered call-graph visualizer for spotting hot paths
  • A Composer package and CLI entry point so it drops into modern PHP projects

Common Use Cases

  • Finding the functions that dominate CPU time or memory on a slow request
  • Comparing profiler runs before and after an optimization to confirm the gain
  • Diagnosing unexpected call-count explosions and N+1-style hot paths
  • Profiling real production-like traffic thanks to the extension’s low overhead

Under The Hood

Architecture - XHProf splits cleanly into a native profiling core (extension/xhprof.c and php_xhprof.h) that hooks PHP’s function-call machinery to record inclusive/exclusive timing, memory deltas, and call counts, and a pure-PHP layer under xhprof_lib for reporting. The xhprof_lib/utils files aggregate raw run data into parent-child edges, xhprof_lib/display renders the sortable HTML report, and callgraph_utils.php emits Graphviz DOT for the call-graph view. Persistence is abstracted behind the iXHProfRuns interface with a default filesystem implementation, so a run flows: enable -> disable returns a data array -> save via a runs backend -> load and render in the UI.

Tech Stack - The profiler itself is a C PHP extension (config.m4 build, ~21% C by bytes) targeting the classic Zend engine hooks; the reporting side is plain PHP requiring only php >= 5.2 with no runtime dependencies. Call-graph rendering shells out to Graphviz (dot), and the report UI is static HTML/JS/CSS. Packaging is Composer-based with a files-autoload entry and a bin/xhprofile CLI.

Code Quality - The code is mature, procedural, and heavily commented with Apache license headers and interface docblocks (iXHProfRuns is clearly documented). It reflects its 2009 Facebook origins: minimal abstraction, global-function API, and no automated PHP test suite beyond the extension’s C tests directory. Naming is consistent and readable, but the style predates modern PSR conventions.

API Design - The public surface is deliberately tiny: xhprof_enable() with optional flags, xhprof_disable() returning a data array, and a runs object to save/load. That minimalism makes it trivial to instrument code, though interpreting the output and wiring up the HTML UI requires reading the bundled docs. The iXHProfRuns interface is the main extension point for teams that need custom storage.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search