xhprof, profiling PHP: Installation & configuration
xhprof is a opensource PHP extension developed by Facebook which allows to profile PHP code. It can be a very powerful tool if you’re able to understand what it outputs, and allows you to optimize your PHP application.
Installation
You’ll have to add a new section in php.ini:
And you’ll create the output directory:
And finally, you’ll just have to install xhprof vizualisation code, and create a virtualhost for it (if you want to):
I’ve created a small script to retrieve quickly all available reports:
Code profiling
To generate a report, you’ll have to start analysis engine and stop it at the end. In the following snippet, you’ll analyse the foo() function code:
Reports will be written in /tmp/xhprof and can be viewable directly with xhprof GUI. For more information, check the xhprof manual.