wpelevator / xhprof
XHProf: A Hierarchical Profiler for PHP
Package info
Type:php-ext
Ext name:ext-xhprof
pkg:composer/wpelevator/xhprof
Requires
- php: >=7.2.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v2.3.11
- dev-fibers-json-export-production-mode
- dev-fork-fix-run-path-traversal
- dev-fork-fix-run-unserialize
- dev-fix-run-unserialize
- dev-fix-run-path-traversal
- dev-windows-builds
- dev-windows-concurrency
- dev-release-2.3.11
- dev-fork-windows-builds
- dev-docker-dev-env
- dev-php8-ui-deprecations
- dev-ci-github-actions
- dev-php85-test-fixes
- dev-fix-_disable-double-free
- dev-fix-ignored-functions-profiling
- dev-master
- dev-add-docker-tooling
- dev-without-initial-fix
- dev-debug
This package is auto-updated.
Last update: 2026-10-29 10:24:04 UTC
README
XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based navigational interface. The raw data collection component is implemented in C (as a PHP extension). The reporting/UI layer is all in PHP. It is capable of reporting function-level inclusive and exclusive wall times, memory usage, CPU times and number of calls for each function. Additionally, it supports ability to compare two runs (hierarchical DIFF reports), or aggregate results from multiple runs.
This is a maintained fork of longxinH/xhprof, published as the PIE package wpelevator/xhprof. Fixes are sent upstream as pull requests too.
PHP Version
PHP 7.2 to 8.5, NTS and ZTS, on Linux, macOS and Windows. CI tests 8.2–8.5 (NTS and ZTS, plus 8.5 with opcache) and 7.2–8.1 (NTS) on Linux, and builds and tests the Windows DLLs.
Installation
PIE
Install with PIE, which builds the extension from source on Linux and macOS and downloads a prebuilt DLL on Windows:
pie install wpelevator/xhprof
From source
git clone https://github.com/wpelevator/xhprof.git ./xhprof
cd xhprof/extension/
/path/to/php/bin/phpize
./configure --with-php-config=/path/to/php/bin/php-config
make && sudo make install
configuration add to your php.ini
[xhprof]
extension = xhprof.so
xhprof.output_dir = /tmp/xhprof
php.ini configuration
| Options | Defaults | Version | Explain |
|---|---|---|---|
| xhprof.output_dir | "" | All | Output directory |
| xhprof.sampling_interval | 100000 | >= v2.* | Sampling interval to be used by the sampling profiler, in microseconds |
| xhprof.sampling_depth | INT_MAX | >= v2.* | Depth to trace call-chain by the sampling profiler |
| xhprof.collect_additional_info | 0 | >= v2.1 | Collect mysql_query, curl_exec internal info. The default is 0. Open value is 1 |
Turn on extra collection
php.ini adds xhprof.collect_additional_info
xhprof.collect_additional_info = 1
Options
xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
XHPROF_FLAGS_NO_BUILTINSdo not profile builtinsXHPROF_FLAGS_CPUgather CPU times for funcsXHPROF_FLAGS_MEMORYgather memory usage for funcs
Example
<?php array( "main()" => array( "wt" => 237, "ct" => 1, "cpu" => 100, ) )
wtThe execution time of the function method is time consumingctThe number of times the function was calledcpuThe CPU time consumed by the function method executionmuMemory used by function methods. The call is zend_memory_usage to get the memory usagepmuPeak memory used by the function method. The call is zend_memory_peak_usage to get the memory
PDO::exec
PDO::query
mysqli_query
$mysqli = new mysqli("localhost", "my_user", "my_password", "user"); $result = $mysqli->query("SELECT * FROM user LIMIT 10");
Output data
mysqli::query#SELECT * FROM user LIMIT 10
PDO::prepare
Convert preprocessing placeholders for actual parameters, more intuitive analytic performance (does not change the zend execution process)
$_sth = $db->prepare("SELECT * FROM user where userid = :id and username = :name"); $_sth->execute([':id' => '1', ':name' => 'admin']); $data1 = $_sth->fetch(); $_sth = $db->prepare("SELECT * FROM user where userid = ?"); $_sth->execute([1]); $data2 = $_sth->fetch();
Output data
PDOStatement::execute#SELECT * FROM user where userid = 1 and username = admin
PDOStatement::execute#SELECT * FROM user where userid = 1
Curl
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.baidu.com"); $output = curl_exec($ch); curl_close($ch);
Output data
curl_exec#http://www.baidu.com
PECL Repository
The PECL package is published from upstream longxinH/xhprof.
Development
Build the extension and run its tests against any PHP version in Docker, without installing a toolchain locally:
make test # PHP 8.5 NTS make test PHP=8.2 VARIANT=zts # another PHP build make test-all # PHP 8.2-8.5, NTS and ZTS
See CONTRIBUTING.md for the other targets (opcache and valgrind runs, older PHP versions, a shell, the report UI) and the Docker setup behind them.
