marjovanlier / xhprof-trace
A library for tracing XHProf performance data in PHP applications.
Requires
- php: ^8.3
- ext-xhprof: *
- symfony/console: ^v5|^v6|^v7
Requires (Dev)
- ext-ast: *
- ext-pcntl: *
- ext-xdebug: *
- enlightn/security-checker: ^v1|^v2
- infection/infection: >=0.27.10
- laravel/pint: ^1.14
- phan/phan: >=5.4.3
- php-parallel-lint/php-console-highlighter: ^1
- php-parallel-lint/php-parallel-lint: ^1
- phpmd/phpmd: ^2
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpunit/php-code-coverage: ^10|^11
- phpunit/phpunit: ^10|^11
- psalm/plugin-phpunit: >=0.18.4
- rector/rector: >=1.0.2
- vimeo/psalm: >=5.22.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- dev-snyk-fix-43b369345a65c8a8a54214a6efedf935
- dev-snyk-fix-d15174a6f40834b554539ff8723cceb1
- dev-Add-Tests
- dev-sweep/sweep_gha_fix_the_github_actions_run_fai_9dbcc
- dev-sweep/sweep_gha_fix_the_github_actions_run_fai
- dev-sweep/update_the_readme
- dev-sweep/the_calculaterank_function_in_the_tracep_71719
- dev-sweep/the_calculaterank_function_in_the_tracep_8d9fd
This package is auto-updated.
Last update: 2026-10-24 09:32:35 UTC
README
XhprofTrace is a PHP library that provides an interface for the XHProf profiling tool. It allows you to enable and disable profiling, and generate and display a report of the profiling data.
Requirements
- PHP 8.3 or higher
- XHProf PHP extension
Installation
Before installing the XhprofTrace library, you need to ensure that the XHProf PHP extension is installed and enabled. If you are using Docker, you can add the following lines to your Dockerfile:
RUN pecl install xhprof && docker-php-ext-enable xhprof
composer require marjovanlier/xhprof-trace
Usage
Here is a basic example of how to use the library:
use MarjovanLier\XhprofTrace\Trace; // Enable XHProf profiling Trace::enableXhprof(); // Your application code here... // Disable XHProf profiling Trace::disableXhprof(); // Display the profiling report in the console Trace::displayReportCLI();
Documentation
The library provides the following static methods:
setProfilesDir(string $path): Sets the folder for the profile files. The default is/var/www/html/profiles/.enableXhprof(): Enables XHProf profiling.disableXhprof(): Disables XHProf profiling and saves the profiling data to a file in the profiles folder. It creates the folder when it does not exist, and saves nothing when profiling was not enabled.displayReportCLI(): Displays a table of every profiled function, summed over all saved runs: the number of calls, the inclusive and exclusive wall time and the exclusive CPU time in milliseconds, the exclusive memory change in kilobytes, and the number of runs. "Exclusive" is the function's own share, without the functions it called. The memory change is negative when a function frees more memory than it takes. The function with the highest exclusive wall time is the last row. A recursive function keeps the names xhprof gives each depth (fib,fib@1,fib@2), so it has one row per depth.
The report adds up every profile file in the folder, also those from earlier sessions. Empty the folder to compare a new set of runs on its own. Files that hold no profile data are skipped.
License
This project is licensed under the MIT License. See the LICENSE file for details.