You are here

Enable Xdebug profiler in Eclipse for PHP CLI scripts

I've been profiling a long-running PHP CLI script using the fantastic Xdebug 2 profiler. I set xdebug.profiler_enable = 1 in my php.ini file, which works great, but I don't always want to generate the resulting ~200MB profiling trace file; sometimes I just want to run the script. This is particularly likely if multiple scripts share the same php.ini file.

The best solution I found is to set the PHP environment variable XDEBUG_CONFIG to profiler_enable=1. In Eclipse (I'm running Eclipse Helios Service Release 2), this can be done in a run configuration ("Run" -> "Run Configurations" -> [your run configuration] -> "Environment" -> "New"). I set up one run configuration for my script as-is and one with XDEBUG_CONFIG set. Easy!

Another way to accomplish this is to have a php.ini file per run configuration, one with xdebug.profiler_enable = 0 and one with xdebug.profiler_enable = 1, but that's a pain to maintain if changes need to be made to both files.

Add new comment