Table of Contents
The following section (Section 4.1, “PHP Source Level Debugging”) describes one of the most interesting aspects when developing software: Debugging.
The second section (Section 4.1, “PHP Source Level Debugging”) within this chapter will describe how you can debug PHPeclipse itself. In case you want to find out how things work, or you found a bug in PHPeclipse and want to help the PHPeclipse developers.
Besides the method of outputting runtime information by adding echo or var_dump functions to your code, the more sophisticated and convenient method is using a so called “Source Level Debugger”.
With the current release of PHPeclipse only DBG is supported. XDebug is currently supported only by directly checking out from the PHPeclipse CVS repository and setting it up appropriately (see Section 1.5.2, “Installing XDEBUG”).
In case you havn't already installed DBG, see Section 1.5.1, “Installing DBG”. When you are sure the DBG module is correctly installed, you can go forward.
To do debugging in PHPeclipse you need to set up a so called “Debug Configuration”. The following sections describe how to set up such a “Debug Configuration” and how to start a debug session.
To set up a “Debug Configuration” click on -> (see Figure 4.1, “Open the Debug Configuration dialog”. Within the opened dialog click on “PHP DBG Script” and click on (see Figure 4.2, “Debug Configuration with the Perspectives view”). This opens the “Create, manage, and run configuration” dialog.
![]() | Note |
|---|---|
The first time you open the configuration dialog, you will see an error message within this dialog, complaining about a missing interpreter setting. For entering the interpreter see | |
Within the “Name:” text field you should change the name (which is “New_configuration” per default) to a more reasonable one (see Figure 4.3, “Set up Debug Configuration - File”).
Within the “File” tab you find two entries:
Project: This is the project this debug configuration belongs to.
File: This is used for “Non Remote Debugging”. The given file is directly given the interpreter which is entered within the Interpreter tab (see Section 4.1.1.4.1, “Configure Environment Interpreter”). And/or is it called when configured for using the internal browser.
These settings are used for “Non Remote Debugging”. If the given Interpreter is directly called by PHPeclipse (see Section 4.1.3, “Debugging CLI”).
Working Directory:
Use default working directory:
Interpreter Arguments: Here you can specify the arguments which will passed to the interpreter (see Using PHP from the command line).
Program Arguments: Here you can specify the arguments which will be passed to your script, and can be accessed by the $argv[] - array.
Within this tab you have to enter the most important settings for a successful debugging session.
Although the setting of the interpreter isn't really necessary for “Remote Debugging”, you have to set it up. For a default XAMPP installation this would be C:\Program Files\apachefriends\xampp\php\php.exe.
The interpreter is used when you set a “Debug Configuration” with “Remote Debug” deactivated. This is true if you want to debug a script which is started per php cli.
Here can you have up to five options to enter:
Remote Debug: You activate this if you want to debug a script which is started from an external browser (this is in opposite of the usage of the browser which is build into PHPeclipse). When you disable this checkbox the appropriate script is forwarded directly to the given interpreter (php.exe)
Cross Platform debugging: Originally used for converting the path seperator (which are different on *nix and Windows systems). As far as I can remember this isn't necessary anymore.
Open with DBGSession URL in internal Browser: Activate this if you don't want to use the an external browser but start a debug session in internal browser.
Remote Sourcepath: The incorrect setting of this path information is responsible for the most annoyances in respect of debugging problems. The “Remote Sourcepath” is important because it is used for translating the path informations which are exchanged between PHPeclipse and DBG. So, if this translation is incorrect, PHPeclipse will not find the correct file which is currently running, nor will DBG know for which file it should set a breakpoint. More different and detailed examples are to come:
Mapped Path: Although in most cases a single path mapping is sufficient, but there are situations where this isn't enough. This is when you use PHP files (e.g. phplib) which are located on a total different path. To use this option, it is necessary to leave the “Remote Sourcepath” field empty. More different and detailed examples are to come:
Used within “Non Remote Debugging”. You can specify variable - value pairs which are passed to the script within the $_ENV and the $HTTP_ENV_VARS array.
When you have done all the necessary settings click on to save the configuration. You can recall this configuration by clicking on the name of the desired configuration in the “Configurations pane” on the left side.
It is called “Remote Debugging” if you want to debug php scripts which are started by web server. This is the case if you are doing so called “Web Devolepment”. In opposite you also can write php scripts and start them from a shell or command line (see Section 4.1.3, “Debugging CLI”.
In contrary to “Remote Debugging” where your php scripts are started by a web server, you could also write scripts and start them from command line[3]. For that task you have to deactivate the “Remote Debug” checkbox (see Section 4.1.1.4.2, “Configure Environment Remote Debug”), and set the appropriate php cli application. According the PHP version you use, this is:
phpcli.exe for PHP 4
php-win.exe for PHP 5
The prerequiste for debugging is also that you have installed dbg as it is described in Section 1.5.1, “Installing DBG”. In addition, for the breakpoints to work, you have to add the following line to the “[debugger]” section of your php.ini:
debugger.JIT_enabled=on
And also you need the following code at the top of your php file you want to debug. At least this code snippet should be located before the first breakpoint you want to set.
if (function_exists ("DebugBreak")) {
DebugBreak ();
}
![]() | Note |
|---|---|
For debugging a php-cli script you need the appropriate PHPeclipse version, which is > phpeclipse-1.1.9-cvs-20060424. This is due to the fact that older PHPeclipse versions listen on port 10001, but dbg uses the standard port 7869, and there is no way to submit a different port neither by cli nor through the php.ini[4]. | |
![]() | Tip |
|---|---|
If you don't want to change the php.ini which you also do use for your web scripts, you can “importy” the appropriate php.ini to your project, and modify this project related local copy of the php.ini file. To use this local php.ini set the “Interpreter Argument” (see Section 4.1.1.3, “Configure Arguments”) as follows: “-c your_project_name/php.ini”. | |
Open Debug perspective. Select a existing debug configuration. Or create a new one. Should see following in Debug View. Internal Browser or external browser. Submit URL in external browser.
A breakpoint can be set by the following methods:
By double clicking within the left vertical ruler of the editor window
Via the left vertical ruler context menu item (see Figure 4.7, “The Editor View left ruler context menu”)
A breakpoint can be removed by the following methods:
By double clicking within the left vertical ruler of the editor window
Via the left vertical ruler context menu item (see Figure 4.7, “The Editor View left ruler context menu”).
Via the “Breakpoints View”, by simple typing Del
Via the “Breakpoints View” context menu item (see Figure 4.5, “The Breakpoints View context menu”)
Via the “Breakpoints View” icon bar “Remove” icon (see Figure 4.6, “The Breakpoints View icon bar”).
A breakpoint can temporary disabled (and enabled) by the following methods:
By clicking into the check box of the appropriate breakpoint within the “Breakpoints View” (see Figure 4.4, “The Breakpoints View”
Via the “Breakpoints View” context menu item (and enabled via ) (see Figure 4.5, “The Breakpoints View context menu”). The context menu commands are related to all selected breakpoints.
You can assign a condition to a breakpoint via the “Breakpoints View” context menu item (see Figure 4.5, “The Breakpoints View context menu”). This opens a dialog (see Figure 4.8, “The breakpoint Properties dialog”). Within the text field “Break Condition” you can set a condition. Don't forget to activate the conditional break via the check box “Enable Condition” at the bottom of the dialog.
For example, if you type “$a == 12” as condition, the program will break if the variable “$a” has the value “12”.
An additional feature to set for breakpoints is the “Skipcounts” condition. Normally the skipcounts is set to 0, which means the program breaks immediately if it scores a breakpoint. If the “Skiptcounts” is set to 1 it means, that the first score of a breakpoint is ignored (skipped) and the second score will lead to a break of the program.
The “Skipcounts” can be set via the same dialog box as the conditional breakpoints (see Section 4.1.5.7.4, “Conditional Breakpoints”). For the “Skipcounts” the checkbox need not to be activated.
![]() | Note |
|---|---|
The “Break Condition” has precedence over the “Skipcounts”. | |
Within the “Variables View” you can see all the variables with their values.
To open the “Variables View” within the “Debug Perspective” go to ->-> (see Figure 4.9, “Open the Variables View”).
![]() | Note |
|---|---|
Be sure that your current perspective is the “Debug Perspective”. Although you can open the “Variable View” within a different perspective, this doesn't make sense. | |
Besides inspecting the value of a variable by looking into the “Variables View” or the “Expressions View” a simple and quick method is to position the mouse pointer over the variable within the source code. Within a second the value and type of the variable is shown (see Figure 4.11, “Show variable value by hovering”).
Within the “Expressions View” you can see the result of an expression. In the simplest form, this is just a variable and the corresponding value. But of course an expression can also be more complex, e.g. a mathematical formula.
There are different ways to open the “Expressions View” and to add an expression.
To open the “Expressions View” within the “Debug Perspective” go to ->-> (see ???).
![]() | Note |
|---|---|
Be sure that your current perspective is the “Debug Perspective”. Although you can open the “Expressions View” within a different perspective, this doesn't make sense. | |
Right clicking on a variable within the “Variables View” opens the context menu. Then click on . This adds the selected variable to the “Expressions View” and opens/activates the “Expressions View”. ->-> (see Figure 4.9, “Open the Variables View”)
| Author | Thread |
|---|---|
| dalong | Published: 2006/11/16 8:00 Updated: 2006/11/16 8:00 |
|
Just popping in
Joined: 2006/11/16
From:
Comments: 2
|
very good!
I like here! ![]() |
|
|
|
| Author | Thread |
|---|---|
| Mark_1900 | Published: 2006/11/18 11:05 Updated: 2006/11/18 11:09 |
|
Just popping in
Joined: 2006/11/18
From:
Comments: 2
|
For an Alias I also had to add a Directory tag to the httpd.conf, otherwise I had permission problems accessing the files...
<br />
[code]
Alias /wiki "C:/Documents and Settings/Me/wiki"<br />
<Directory "C:/Documents and Settings/Me/wiki"><br />
Options Indexes MultiViews<br />
AllowOverride None<br />
Order allow,deny<br />
Allow from all<br />
</Directory><br />
[/code]<br />
Oh and all these editing tags seem broken!!
![]() |
| Author | Thread |
|---|---|
| Mark_1900 | Published: 2006/11/18 11:21 Updated: 2006/11/18 11:32 |
|
Just popping in
Joined: 2006/11/18
From:
Comments: 2
|
I want a debugger. I downloaded the latest XAMPP 1.5.4a and noticed that it comes with PHP 5.1.6 & PHP 4.4.4, and neither are supported. The debugger module only supports a subset of these major versions from 5.1.0 to 5.1.2 and 4.4.0 to 4.4.2 (http://dd.cron.ru/dbg/downloads.php). I think right at the beginning you should specify which versions to download to get a debugger Version "XAMPP 1.5.2" would be fine.
|
| Author | Thread |
|---|---|
| huqilong | Published: 2006/11/30 6:28 Updated: 2006/11/30 6:28 |
|
Just popping in
Joined: 2006/11/16
From:
Comments: 3
|
I want to know how to use phpeclipse with eclipse detailly!
|
| Author | Thread |
|---|---|
| thierrybo | Published: 2007/2/3 16:19 Updated: 2007/2/3 16:21 |
|
Just popping in
Joined: 2007/2/3
From:
Comments: 1
|
I do not agree with the suggested method 2:
Quote:
For example you have set up XAMPP and your “document root†path is the XAMPP default:
C:Program Filesapachefriendsxampphtdocs
,then your appropriate workspace path should be one level less:
C:Program Filesapachefriendsxampp
|
| Author | Thread |
|---|---|
| dafydd | Published: 2007/4/3 6:01 Updated: 2007/4/3 6:01 |
|
Just popping in
Joined: 2007/4/3
From:
Comments: 2
|
Trying this out on a Mac. J2SE 1.5.0_07-164 installed. 1.5.0_06 is what's available on the download site. However, it would almost certainly be updated with Software Update.
|
| Author | Thread |
|---|---|
| dafydd | Published: 2007/4/6 1:00 Updated: 2007/4/6 1:00 |
|
Just popping in
Joined: 2007/4/3
From:
Comments: 2
|
Second question: How do we point the XAMPP start/stop buttons in the Eclipse toobar to where we put XAMPP?
dafydd |
| Author | Thread |
|---|---|
| dysmas | Published: 2007/8/4 14:18 Updated: 2007/8/4 14:18 |
|
Just popping in
Joined: 2007/8/4
From:
Comments: 1
|
Thanks hundred times for all the detailed explanations here !!
And especially for the note which explains why debugging a CLI application does not work in 1.1.8 version and only in 1.1.9. (wrong port, as I guessed, but I have been looking for this information for some hours before coming here). Unfortunately this 1.1.9 CVS version does not work in the last 3.2.0 Eclipse version I just got. Let us hope the stable version is going quickly. |
| Author | Thread |
|---|---|
| Mercyful | Published: 2007/9/10 14:46 Updated: 2007/9/10 14:46 |
|
Just popping in
Joined: 2007/9/10
From:
Comments: 1
|
I want using eclipse3.2 with php-plugin and for debugging i want using dbg.
I'm using xampp 1.6.3a with php 4.4.7. and php_dbg.dll-4.4.x After step by step installation http://docs.schuetzengau-freising.de/ ... =xo-002&file=ch01s05.html the debugger dbg will not work. When i called phpinfo() there is no section dbg shown. Who have any ideas? Thanks a lot! Regards Mercyful |
| Author | Thread |
|---|---|
| keryx | Published: 2007/9/26 22:59 Updated: 2007/9/26 22:59 |
|
Just popping in
Joined: 2007/9/26
From:
Comments: 1
|
A section about verrors should be nice. I get the following:
<terminated, exit value: 0>PHP C:\Program\PHP\php.exe : <path>/<fil>.php I've googled like crazy but to no avail. And yes - it does not stop at breakpoints and "variables" are empty. DBG is working: if (function_exists ("DebugBreak")) { DebugBreak (); echo "debugging started!<br />\n"; } Outputs "debugging started!" And DBG is reported on phpinfo(). |
| Author | Thread |
|---|---|
| koski | Published: 2007/10/19 3:55 Updated: 2007/10/19 3:55 |
|
Just popping in
Joined: 2007/10/19
From:
Comments: 1
|
Hi,
Seems that the mentioned link for cvs: http://phpeclipse.sourceforge.net/update/cvs is out of date or wrong. |
| Author | Thread |
|---|---|
| andybruk | Published: 2007/11/18 1:11 Updated: 2007/11/18 1:11 |
|
Just popping in
Joined: 2007/11/18
From:
Comments: 1
|
I've been searching for a PHP debugger for ages. This is the only one I can find that works perfectly, thanks very much for providing this documentation.<br /><br />I doubt if I could ever get it to work on Windows, but it works so well with Ubuntu Linux and Eclipse 3.1.<br />
|






![[Note]](docs/en/xo-002/img/admon/note.png)



![[Tip]](docs/en/xo-002/img/admon/tip.png)










