Much has been written about debugging PHP in eclipse, yet for all the blogs and tutorials I have had no end of problems. My setup was complicated by the fact that I was trying to debug command-line scripts using the symfony framework. Only the last part was really symfony-dependent, however. Here is what finally worked for me.
My setup:
- Windows XP
- PHP 5.2.6
- Eclipse 3.3
- Symfony 1.0.11
Debugger Choice: Zend
First I needed to decide on a debugger. In the end I found that Xdebug caused nasty PHP crashes at the end of some runs. I’m not sure why I had this problem, but I wound up using Zend.
Eclipse, servers, and clients
Eclipse 3.3 comes with debug clients for Xdebug and Zend debugger built-in. If you look in Window -> Preferences, PHP -> Debug -> Installed Debuggers, you should see them there. This does not mean, however, that you have everything you need ready to go.
PHP must also be configured (in php.ini) with debugging support. This involves loading an extension for Zend debugger or Xdebug. Eclipse comes with a version PHP configured with Zend debugger. On my system it was here:
C:\Program Files\eclipse\plugins\org.zend.php.debug.debugger.win32.x86_5.2.10.v20070905\resources\php5\php.exe
The key to this is that in that same directory is a php.ini that loads ZendDebugger.dll (also in the same directory).
Furthermore, Eclipse seems to require that your PHP have debugging support built in, even when you Run (not Debug).
Other considerations
The Zend debugger slows down PHP significantly. I didn’t want to have it enabled by default. So, I created a separate ini file that includes the Zend debugger and told Eclipse to use it.
My code used MySQL, so I needed at least that extension loaded in PHP.
The Steps
- Install everything (Apache, PHP, Eclipse, Symfony, etc.)
- Find ZendDebugger.dll in your eclipse plugins dir (see path above for a hint)
- Copy it to your PHP extensions dir (a subdir of your main PHP dir)
- Create a copy of php.ini called php-debug.ini
- In php-debug.ini add the following (substituting in the proper path to PHP):
- In Eclipse, go to Window -> Preferences, PHP -> PHP Executables
- Click Add
- Specify a name that you will recognize
- In Executable path, find your standard php.exe (not part of Eclipse)
- In config path, specify php-debug.ini
- Choose Zend Debugger
- Add
- Now, to run or debug you will need to choose the PHP Executable that you created.
zend_extension_ts=”C:/Program Files/PHP/ext/ZendDebugger.dll”
Symfony
To make it work with symfony, create the following file, named bootstrap.php, in your project root dir:
<?php
// From symfony.bat
ini_set(’html_errors’, ‘0′);
ini_set(’open_basedir’, ”);
// ‘Calls’ the php script symfony
require(’./symfony’);
?>
Then, to run a symfony command, for example symfony test-unit Foo, you would do the following:
- Go to Run -> Open Run Dialog (or Open Debug Dialog)
- Make sure PHP Debugger and PHP Executable are set correctly.
- Specify bootstrap.php as the php file to run
- In the php script arguments, put the symfony parameters (e.g. test-unit Foo)
For regular symfony commands you would still do it straight from the command-line, or using Symfoclipse. This is useful for unit tests and the like where it would invoke your code.
Problems
Sometimes, PHP executables that are created are not made available in the Run or Debug dialogs. I don’t know why, but creating new PHP executables (without removing the old ones first) seems to work around the problem.
October 20, 2008 at 9:27 am |
It was very helpful… Thanks for the content…!!