xdebug + webgrind で PHP プロファイリング

出来上がったPHPのプログラムが遅いので、ボトルネックを調べることになった。
そういえば、xdebug でプロファイリングしてたなぁと思ってググってみたら、
webgrind というWebベースのフロントエンドがあることが分かった。

http://code.google.com/p/webgrind/

インストールで参考になりそうなサイトはこちら↓
http://anantgarg.com/2009/03/10/php-xdebug-webgrind-installation/

xdebug をインストール

 $ sudo aptitude install php5-xdebug

/etc/php5/conf.d/xdebug.ini に以下の設定を追加する。

xdebug.profiler_enable = 1
xdebug.profiler_output_dir = /tmp
xdebug.profiler_output_name = cachegrind.out.%p

Apacheのドキュメントルートの下に、webgrind のアーカイブ(zip)を展開する。

 $ unzip webgrind-release-1.0.zip

webgrind の config.php を設定(デフォルトのままでも大丈夫だった)。

static $storageDir = '';
static $profilerDir = '/tmp';

webgrind のディレクトリ内は、プロファイリングを無効にする。これ結構重要。
.htaccess などで Apache を設定するとよい。
httpd.conf で ArrowOverride の設定をしておかないと、.htaccessphp_flag の設定は出来ないので注意。)

php_flag xdebug.profiler_enable 0