knackforge
July 28, 2015
XHProf is a hierarchical profiler for PHP. It reports function-level call counts and inclusive and exclusive metrics such as wall (elapsed) time, CPU time, and memory usage. A function's profile can be broken down by callers or callees. The raw data collection component is implemented in C as a PHP Zend extension called xhprof. XHProf has a simple HTML-based user interface (written in PHP). The browser-based UI for viewing profiler results makes it easy to view results or to share results with peers. A callgraph image view is also supported.
I made sure xhprof-0.9.2 was installed inside the www-directory of the webserver.
wget http://pecl.php.net/get/xhprof-0.9.2.tgz |
tar xvf xhprof-0.9.2.tgz |
cd ./xhprof-0.9.2/extension/ |
phpize |
./configure --with-php-config=/usr/local/bin/php-config |
sudo make |
sudo make install |
sudo make test |
The php-config file on my machine was located in /usr/local/php-config . Php-config is a file that lists the location of your php-installation. Xhprof needs it for its configuration. If you cannot find the file, you can simply execute ./configure without the parameter.
If phpize is not found, you have to install php5-dev
sudo apt-get install php5-dev
The first time, install and the make test both failed with me, but xhprof worked nevertheless.
In php.ini I set up this at the end of the file:
[xhprof] |
extension=/path/to/xhprof-0.9.2/extension/modules/xhprof.so |
xhprof.output_dir="/var/tmp/xhprof" |
Create the directory: /var/tmp/xhprof
xhprof will keep its logfiles in there (files that are needed for the page analysis)
Create an entry for /path/to/xhprof-0.9.2/ in your webserver’s configuration (point xhprof.localhost to the /path/to/xhprof-0.9.2/. If local, setup your hostfile correctly (eg: 127.0.0.1 xhprof.localhost)
Restart PHP and your webserver.
When using Drupal, install Devel, and activate the XHProf settings (admin/settings/devel) and point to /path/to/xhprof-0.9.2/ and the path to the website: http://xhprof.localhost/xhprof_html
Devel will create a link at the end of each page that points to XHProf.
If you get the error that the function xhprof_enable is unknown, then it’s because XHProf wasn’t properly installed. Try to install it again and make sure you have restarted php.
If the link in Drupal to XHProf doesn’t work, check if the run parameter in the url is supplied. If not, try to install XHProf again and make sure you have restarted php. A typical error for this is: “No XHProf runs specified in the URL.”
For errors concerning php-config and phpize, see above.
Just like how your fellow techies do.
We'd love to talk about how we can work together
Take control of your AWS cloud costs that enables you to grow!