Identify Bottleneck on your PHP Scripts with XDebug Code Trace

XDebug has been around for a while and I have been looking to try its features for a while. This time, I was able to poke around briefly with dumping code traces for my PHP code.

1. Make sure to have XDebug extension installed, you can either do so from your OS package management or build from source. For this exercise I have installed version 2.1.

2. Enable the extension on your PHP configuration file.

3. For the xdebug.trace_output_dir path, make sure it is writable by the HTTP user, in this case I have Apache and the user is, obviously, apache too.

4. Test your script! Note that every execution or request will generate a code trace dump and by default they will be overwritten. You can set xdebug.trace_options to 1 to create new file per request. Ideally, this is only done on your testing environment 🙂

Here’s a sample output of a code trace: