XHGui needs version numbers or fluffy animal names, because this is a really major release and quite different to what went before in both technology and in looks. In particular, it now uses MongoDB. If you’re not familiar with MongoDB, it’s a super-friendly NoSQL database that makes a really handy backend for this kind of unstructured data – because every run of every page will look different. Therefore you will need:
- MongoDB itself
- The pecl extension for mongo
- The xhprof pecl extension (
read on if you’re using PHP 5.4, there’s a gotcha)
To get MongoDB, go to http://www.mongodb.org/ and find the instructions for your system. I use their apt repositories since they update quicker than Ubuntu’s (for obvious reasons) and Mongo is a pretty young product so it updates a lot.
The pecl extension for Mongo should be easy enough:
pecl install mongo
The XHProf extension should be that easy, but isn’t. There’s an
xhprof-beta package available, but I found that this did not work when installed on my system. This turns out to be because it’s not ready for PHP 5.4, so follow the instructions at http://michaelsanford.com/compiling-xhprof-for-php-5-4/ for now. The change is in the github project, so I assume facebook will roll a new release of xhprof at some point. This was the most difficult bit of setup for me so if you get this far, you’re almost there!
Many thanks to the facebook engineers for rolling a pecl release that will work with 5.4+ as well as the earlier versions. You simply need to do:
pecl install xhprof-beta
And you’re good to go.
You’ll find the main project here: https://github.com/preinheimer/xhgui and I forked the repo onto my github account and cloned that, you could download the code direct from their repo, it doesn’t matter. The project README is great and will show you how to set up, making the cache directory writeable and adding a line to enable profiling to your virtual host configuration (don’t forget to restart Apache).
At this point, you’re logging data when you make requests to whichever virtual host you added XHGui to, but how do you see the results? Set up another virtualhost (or if you’re lazy like me, start the PHP 5.4 webserver instead) for the directory
/web/webroot and then request it. You will see a list of all the requests you have made, with the option to filter these in various ways. You can also drill into the detail for an individual request:
From this point you can start to drill in and look at all the various statistics collected by XHGui, identify pain points in your application, and compare two runs to measure how much you have improved things when you optimise.
I have only recently looked at the two XHGui based projects I’ve worked on and asked “Oh Gosh, what have I done‽. I’m open to suggestions on how to resolve this naming conundrum.
I’m very glad my post on compiling xhprof helped!
As a side-note, the last pecl-packaged release of xhprof (0.9.2) was bundled mid-2009; I doubt they’ll *ever* release an updated one.
As a matter of fact, they did !
Last week 0.9.3 was released :-)
I haven’t tried it myself yet though..
Lorna, since you asked so nicely ;-)
I’ve rolled an updated pecl package from the current tip of our github repo and pushed it to the pecl site.
I very briefly tested the package before inflicting it on the world; it seemed to work for me, but YMMV!
Double checked that `sudo pecl install xhprof-beta` does something reasonable. Enjoy!
Thankyou!! Happy to have established the precedent that bribery will probably work :)
The new callgraph is not very useful, unless you miss lava lamps. Filtering by domain is absent, as is access control. Gotta go back to the older ver. It was fun to play with, though! :)
Pingback: Saving cycles… O’rly? (Stupid Series) | CrazyCodr's blog