So, recently I felt the need to do some profiling on an ExpressionEngine website I was working on which was running slower than I’d like. I remember using a nifty tool called Webgrind back when I was developing on Windows with WAMP, and since I’m currently using AMPPS on OSX I thought I’d get Webgrind up and running on that.
Webgrind is basically a lightweight web app which displays PHP profiling data (generated by the PHP xdebug profiler) in your web browser. To get things up and running we need to do a few things – install the xdebug extension to our AMPPS PHP installation, enable xdebug profiling in php.ini, and then install and configure Webgrind.
Installing xdebug in AMPPS
Head over to http://code.activestate.com/komodo/remotedebugging/ and download “PHP Remote Debugging Client” Mac OSX (universal) version. Unzip the file you just downloaded, and navigate to the folder corresponding to the PHP version you want to install for, which in my case was 5.3. In that folder should be a file named “xdebug.so”, copy this file into the extensions folder for the PHP version you’re using in your AMPPS installation. So if you’re using 5.3, copy the xdebug.so file into “/Applications/AMPPS/php-5.3/lib/extensions/ext/” folder.
To enable xdebug, you need to edit your php.ini file, which for PHP 5.3 should be at “/Applications/AMPSS/php-5.3/etc/php.ini”, and add the following lines, just above the Dynamic Extensions section towards the bottom of the file:
[XDebug] zend_extension=/Applications/AMPPS/php-5.3/lib/extensions/xdebug.so xdebug.remote_enable=1 xdebug.profiler_enable=1 xdebug.profiler_output_dir=/Applications/AMPPS/tmp
Now just restart Apache and xdebug should start creating cachegrind files to your AMPPS tmp directory.
Webgrind is real simple to install, just download it from https://code.google.com/p/webgrind/, and unzip it into a folder in your localhost – something like “/Applications/AMPPS/www/webgrind” will work great. Lastly we just need to edit the webgrind config to read the cachegrind files generated by xdebug, as by default webgrind isn’t looking in the correct location. Open up “/Applications/AMPPS/www/webgrind/config.php” in an editor and change the line “static $profilerDir = ‘/tmp’; ” to “static $profilerDir = ‘/Applications/AMPPS/tmp’;”, which should be around line 19.
Finally, make sure AMPPS Apache is started, fire up your favourite browser, and head to “http://localhost/webgrind” and start profiling your web apps in detail.
WARNING: xdebug cachegrind files can be pretty big (actually bloody massive), and can fill up a hard drive pretty quick, so you probably wont want xdebug profiling turned on all the time. So save yourself a headache and disable xdebug profiling when you’re not using it – simply comment out “xdebug.profiler_enable=1” by adding a semi-colon (;) at the start of the line in your php.ini and restart your Apache. It also wouldn’t harm to empty out /Applications/AMPPS/tmp when you’re done profiling too.