Xdebugを使う

phpデバッグXdebugを使うようにした.環境はFreeBSD7.0-RELEASE.以下導入メモ.Xdebugportsからインストール.

# cd /usr/ports/devel/php-xdebug
# make install
*****************************************************************************
The php debugger 'xdebug' has been installed successful.
Add a line containing

    extension=/usr/local/lib/php/20060613/xdebug.so

or

    zend_extension=/usr/local/lib/php/20060613/xdebug.so

to your php.ini to load it. xdebug is not compatible with the extension
'Zend Optimizer' - you're only able to use one of them. So take care having
at least the lesser required extension disabled by commenting out it's
loader line in your php.ini.

Add following section to enable profiling:

xdebug.profiler_enable = 1
xdebug.profiler_output_dir = /tmp/profiler

*****************************************************************************
===>   Registering installation for php-xdebug-2.0.2

指示に従い,php.iniに以下を記述*1

zend_extension=/usr/local/lib/php/20060613/xdebug.so

apacheを再起動するなりするとXdebugが使用可能となるはず.

$ php -m 
(省略)
[Zend Modules]
Xdebug

Zend Modules に XdebugがあればOK*2.

プロファイラの設定

# vi /usr/local/etc/php.ini
// 以下を記述
xdebug.profiler_enable=1
xdebug.profiler_output_dir = "/var/log/xdebug/" // ログを吐き出させたい場所.

ディレクトリの準備およびapache再起動

# mkdir /var/log/xdebug
# chown www /var/log/xdebug
# apachectl restart

吐き出されるログはそのまんまだと見難いため,WinCacheGrindやKcacheGrindIndexで閲覧する.

*1:extension=/usr/local/lib/php/20060613/xdebug.so でもよいが,その場合コマンドラインから実行すると,PHP Warning: Xdebug MUST be loaded as a Zend extension in Unknown on line 0 といった警告がでる.ブラウザ上からしか確認しない場合は,どちらでもよい

*2:zend_extensionで読み込んだ場合