I read a really comprehensive article from iBuildings (Lorenzo Alberton) this week with regards to setting up the XHProf Facebook Profiling Extension. I set this up at work on my Ubuntu machine without any issues and was profiling within about 15 minutes. I already had XDebug and KCacheGrind setup at work, but wanted to try this out, mainly due to being able to see the results from within the browser, and simply being able to drop in two values into the .htaccess file.
Tonight, I wanted to get this up and running on my Snow Leopard machine at home, to do some profiling for my site which is running Zend Framework. Sadly I came across a few issues which I wanted to highlight incase other people had the same problems.
First off, I encountered the issue Lorenzo mentioned in his post about not being able to find config.m4, which was easily rectified by carrying on with Lorenzo’s guide. After this, I then ran into issues with phpize:
grep: /usr/include/php/main/php.h: No such file or directory grep:
/usr/include/php/Zend/zend_modules.h: No such file or directory grep:
/usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
This is related to the fact I upgraded from Leopard to Snow Leopard and didn’t upgrade my developer tools (Slap wrists). If you upgrade your xCode installation to 3.2 which can be found in the “Optional Installs” folder on the Snow Leopard Install DVD this will then deal with this for you. Once that is done, you can continue:
$/usr/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
Then you can run the configure and make commands
./configure --with-php-config=/usr/bin/php-config
make
sudo make install
make test
Once all that is done you can edit your php.ini settings:
[xhprof]
extension=xhprof.so
xhprof.output_dir="/tmp/xhprof"
For ease of use in the future I then moved the two folders needed to make all this work to /Users/Ben/Sites/xhprof
$ ~/Desktop/xhprof-0.9.2$ mkdir ~/Sites/xhprof
$ ~/Desktop/xhprof-0.9.2$ mv xhprof_lib/ ~/Sites/xhprof/
$ ~/Desktop/xhprof-0.9.2$ mv xhprof_html/ ~/Sites/xhprof/
I have defined my header and footer files exactly like Lorenzo suggested in his article and then pre/appended these files using the .htaccess file
header.inc.php:
<?php
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
footer.inc.php:
<?php
$xhprof_data = xhprof_disable();
include_once "/Users/Ben/Sites/xhprof/xhprof_lib/utils/xhprof_lib.php";
include_once "/Users/Ben/Sites/xhprof/xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof");
error_log("nnn***nnhttp://localhost/xhprof/xhprof_html/index.php?run=$run_id&source=xhprofnn***nnn");
.htaccess file:
php_value auto_append_file /Users/Ben/Sites/xhprof/footer.inc.php
php_value auto_prepend_file /Users/Ben/Sites/xhprof/header.inc.php
I now have the XHProf Extension up and running on my Snow Leopard machine.
Thanks to Lorenzo Alberton for his extensive article