For those interested in debugging a PHP script, you might consider using xhprof on your server. The following guide will cover installation of this component on a cPanel machine for a single account:
1. Pecl installation
Since xhprof is a beta module for PHP, the following command will not work:
You may see the following error on phpize for the pecl installation:
2. Adding xhprof to php.ini
Edit /usr/local/lib/php.ini to add the following at the bottom:
3. Creating the temporary session directory
4. Checking xhprof shows up as a PHP module
5. Install graphviz for graphical information
6. Copy all the xhprof directories to /usr/local/lib/php
7. Create a list.php file for the /tmp/xhprof sessions
Place the following contents in that file:
8. Testing a php script
Create the following at /home/username/public_html/php.php location (where username is the cPanel account username):
If you are using DSO, you can then symlink the global directories:
If you are using suPHP, you would need to copy the directories:
You should then be able to load the http://domain.com/xhprof/xhprof_html/list.php page to see a listing of all /tmp/xhprof sessions. Click on the session to view the data. Please replace domain.com with the domain on the cPanel user's account where you created the code and linked / copied the files.
I've attached a screen print of an example of both http://domain.com/xhprof/xhprof_html/list.php and clicking on one of the sessions for the result data.


Due to the data being sent, you may well want to password protect the /home/username/public_html/xhprof directory using cPanel > Password Protect Directories area.
1. Pecl installation
Since xhprof is a beta module for PHP, the following command will not work:
The following command should work:# pecl install xhprof
Failed to download pecl/xhprof within preferred state "stable", latest release is version 0.9.2, stability "beta", use "channel://pecl.php.net/xhprof-0.9.2" to install
install failed
Code:
pecl install channel://pecl.php.net/xhprof-0.9.2
If so, then do the following to manually configure xhprof on the machine:running: phpize
Cannot find config.m4.
Make sure that you run '/usr/local/bin/phpize' in the top level source directory of the module
ERROR: `phpize' failed
Code:
cd /root/tmp/pear/cache/xhprof-0.9.2/extension
phpize
./configure --with-php-config=/usr/local/bin/php-config
make
make install
Edit /usr/local/lib/php.ini to add the following at the bottom:
Code:
[xhprof]
extension=xhprof.so
xhprof.output_dir=/tmp/xhprof
Code:
mkdir /tmp/xhprof
chmod 777 /tmp/xhprof
Code:
php -m | grep -i xhprof
Code:
cd /
wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.28.0.tar.gz
tar xzf graphviz*
cd graphviz*
./configure
make && make install
Code:
cd /root/tmp/pear/cache
cp -r xhprof-0.9.2 /usr/local/lib/php/xhprof
Code:
touch /usr/local/lib/php/xhprof/xhprof_html/list.php
Code:
<?php
$path = '/tmp/xhprof/';
foreach(glob($path."*") as $file) {
$tmp = pathinfo($file);
echo "<a href=\"index.php?run={$tmp['filename']}&source={$tmp['extension']}\">{$tmp['filename']}</a><br/>";
}
?>
Create the following at /home/username/public_html/php.php location (where username is the cPanel account username):
Code:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
// Start profiling
xhprof_enable();
// A basic PHP test
echo '<p>Hello World</p>';
echo date("M-d-Y");
// Stop profiling
$xhprof_data = xhprof_disable();
//
// Saving the XHProf run
// using the default implementation of iXHProfRuns.
//
include_once "/usr/local/lib/php/xhprof/xhprof_lib/utils/xhprof_lib.php";
include_once "/usr/local/lib/php/xhprof/xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
// Save the run under a namespace "my_xhprof_foo".
$run_id = $xhprof_runs->save_run($xhprof_data, "my_xhprof_foo");
?>
</body>
</html>
Code:
cd /home/username/public_html
mkdir xhprof && cd xhprof
ln -s /usr/local/lib/php/xhprof/xhprof_html .
ln -s /usr/local/lib/php/xhprof/xhprof_lib .
Code:
cd /home/username/public_html
mkdir xhprof && cd xhprof
cp -r /usr/local/lib/php/xhprof/xhprof_* .
I've attached a screen print of an example of both http://domain.com/xhprof/xhprof_html/list.php and clicking on one of the sessions for the result data.


Due to the data being sent, you may well want to password protect the /home/username/public_html/xhprof directory using cPanel > Password Protect Directories area.