Xhprof + PHP5.4 + Ubuntu + Chamilo 1.10dev

(Read the update below before starting to copy-paste)

To install Xhprof on PHP5.4 on Ubuntu (assuming you’ve already got PHP5.4 from Andrej or somewhere safe) in order to measure the load of Chamilo 1.10 dev (you need to have a mercurial clone, otherwise the “tests” directory will not exist), follow this procedure (all lines prefixed with # are comments):

cd /tmp
sudo apt-get install php5-dev php-pear
pecl bundle xhprof
cd xhprof

# Here you will have to apply the patch mentioned here: https://bugs.php.net/bug.php?id=61674 to your extension/xhprof.c file (otherwise it won’t compile with PHP 5.4).

sudo make install

UPDATE 10/2014: On Ubuntu 14.04, you can now install Xhprof with just:

sudo apt-get install php5-xhprof

Then edit the config file

 sudo vim /etc/php5/apache2/conf.d/20-xhprof.ini


# Add the following:


# Save

# In your VirtualHost definition (or simply in your /etc/php5/apache2/php.ini), declare the auto_prepend_file and auto_append_file config vars:

 php_value auto_prepend_file /var/www/chamilo/tests/xhprof/header.php
 php_value auto_append_file /var/www/chamilo/tests/xhprof/footer.php


# Now restart Apache:

sudo /etc/init.d/apache2 restart

Load your Chamilo page. You should now see a little “Profiler output” link in the bottom left corner of the page. That’s it, you can now use Xhprof.


There are a few nice hidden features in xhprof, like the possibility to *compare* two page loads. Search the web for more info (e.g. Viewing a Diff Report).


Notes @2014-03-20:

  • Following recent tests, it appears like you have to go into the “/tmp/xhprof/extension” directory before launching “phpize” as indicated above
  • If you installed PHP5.5 on a recent version of Ubuntu, you will find that most of the above is unnecessary, and that you can simply launch a “sudo apt-get install php5-xhprof” and then create your 20-xhprof.ini file, and you’ll have xhprof running
  • You might need to update the path in chamilo/tests/xhprof/footer.php, as it is currently hardcoded to “my.chamilo.net”. Make sure you give it the address that you are really using