binfer / php-xh
A example xhprof package
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:vcs
pkg:composer/binfer/php-xh
Requires
- php: >=5.3.3
- ext-curl: *
- ext-pdo: *
- ext-pdo_mysql: *
This package is auto-updated.
Last update: 2025-09-29 02:42:08 UTC
README
To begin with, you need to install the XHProf extension. Refer to the PHP documentation if you need assistance.
You will need to manually create the database and populate it with the provided scheme. The database scheme is located at /setup/database.sql.
Rename the /xhprof/includes/config.inc.sample.php to /xhprof/includes/config.inc.php. There are only two supported parameters.
xhprof_urlis the URL to the XHProf.io library.pdois the PDO instance. This library uses PDO to handle all of the database operations.enableis a closure to control when enable data collection, return true means always enable
Some cases for reference:
Alway enable
'enable' => function() { return true; }
Enable if url contents debug parameter:
'enable' => function() { if (!empty($_GET['debug'])) { return true; } }
Enable for 1/100 probability
'enable' => function() { return rand(0, 100) === 42; }
Enable for url path is /:
'enable' => function() { if (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) === '/') { return true; } }
For XHProf.io to start collecting data, you need /inc/inject.php files included to every file of interest. The recommended approach is to update your php.ini configuration to automatically prepend and append these files.
auto_prepend_file = /[absolute path to xhprof.io]/inc/inject.php
If you use nginx, you could configuration auto_prepend_file as a fastcgi_param
fastcgi_param PHP_VALUE "auto_prepend_file=/[absolute path to xhprof.io]/inc/inject.php";
If you are using PHP-FPM, then XHProf.io will utilise fastcgi_finish_request to hide any overhead related to data collection. There is nothing to worry about if you are not using PHP-FPM either, as the overhead is less than a few milliseconds.