Using Webgrind and Xdebug, you to tack on ?XDEBUG_PROFILE=true to any URL and view profiling information for that particular URL instantly.
One of the main criticisms of profiling PHP applications has been how difficult it is to manage different kcachegrind or wincachegrind windows — assuming you’re a pro at pointing them to your Xdebug output directory and all that good stuff. I am excited about how easy webgrind makes things because easier profiling will help prevent a lot of stupid performance mistakes (for those of us not using the Zend IDE and its sexy profiler, which is a lot of people).
This is really quite simple to set up, and is best used on a dev box behind a firewall with port 80 closed. People can file surf your web server if you leave webgrind on an open port, don’t do it.
So, you’ve read the last paragraph, right? Ok, good. Let’s go.
Use pecl to install the json and xdebug packages
pecl install json
pecl install xdebug
You’ll run into a possible missing phpize issue, in which case you’d need the php-devel package for building PHP extensions.
A simple configuration to get you what you need is below. Read the Xdebug docs if you want to get crazy.
; Enable xdebug extension module
; Turns it off by default
; Turns xdebug on when ?XDEBUG_PROFILE=true is in GET or POST
; Your output directory - you'll eventually point webgrind at this
If you’re not on PHP 5.2.x, you’ll also need the json extension.
; Enable json extension module
Download and install webgrind
Webgrind is easy to setup, download it and follow the instructions. The main thing you’ll want to do is make sure your Xdebug directories are the same. In this case, it’s /tmp/xdebug
Load any PHP app with ?XDEBUG_PROFILE=true
Now you’ll want to hit your web server with the appropriate GET argument set up. So, you could hit localhost/helloworld?XDEBUG_PROFILE=true and it’d create a new cachgrind.out for that request.
Open up a tab with webgrind in it and enjoy
Update: You should use “zend_extension” in your .ini file, not extension. I had a typo above, but it’s corrected.