arrow_back
Back

XHProf: hierarchical PHP profiling and call graphs

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

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.

Maintained forks

There are two main maintained forks of the xhprof extension:

Installation of longxinH/xhprof (PECL)

# Docker PHP-based image:
install-php-extensions xhprof

Set a parameter for the output dir in php.ini:

xhprof.output_dir = /tmp/xhprof

How to use it:

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);

// .. code

$xhprof_data = xhprof_disable();

print_r($xhprof_data);

We can use tools from the library to analyze the reports:

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);

// .. code

$xhprof_data = xhprof_disable();

include_once "/app/web/xhprof_lib/utils/xhprof_lib.php";
include_once "/app/web/xhprof_lib/utils/xhprof_runs.php";

$xhprof_runs = new \XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");

echo "http://localhost/xhprof_html/index.php?run={$run_id}&source=xhprof_testing\n";

You can find the tools in the GitHub repository.

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward