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 zend_extension=xdebug.so ; Turns it off by default xdebug.profiler_enable=0 ; Turns xdebug on when ?XDEBUG_PROFILE=true is in GET or POST xdebug.profiler_enable_trigger=1 ; Your output directory - you'll eventually point webgrind at this xdebug.profiler_output_dir=/tmp/xdebug
If you’re not on PHP 5.2.x, you’ll also need the json extension.
; Enable json extension module extension=json.so
Download and install webgrind
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.