Home » Products » UltraEdit/UEStudio » Getting Started

Debugging PHP Scripts

As of version 4.3.0, PHP supports a new SAPI type (Server Application Programming Interface) named CLI which means Command Line Interface.  If you're running the latest version of PHP, you will be able to execute PHP scripts either in a browser (using the Apache server and PHP scripting engine) or from the command line (using only the PHP scripting engine).  Through the integration of Xdebug, users of UEStudio can debug both browser-based PHP scripts or command line PHP scripts.

 

Before debugging can occur, the PHP scripting engine and Xdebug must be downloaded and installed.  Please click here for instructions on how to download and install these components and configure them appropriately based on whether you will be debugging browser-based PHP scripts or command line PHP scripts.  Once you've installed and configured PHP and Xdebug on your system, debugging your PHP scripts is just a few steps away:

 

1. Create a default PHP debugging project in UEStudio.  This PHP debugging project is only used to store settings specified for the PHP debugger.  PHP scripts do not have to be associated with the active project in any way for debugging to occur.

  a. Go to New Project/Workspace in the Project menu and select "Create New Project..."

  b. Enter a name for your new project, e.g.: "PHPDebug" and press the Save button.

  c. Click on the Debug tab and select "Integrated Xdebug" from the Select Project Debugger dropdown and press the Close button.

  

2. In the Build menu select Start Debugger to initiate the Xdebug debugging session.  When Xdebug is invoked a dialog will appear:

 

 

At this point you may press "OK" and proceed as indicated in the dialog:

 

Browser Based PHP Debugging

1. After pressing "OK" in the Listening for Connection... dialog, you will see

 

Xdebug: Listening for connection...

 

in the status bar.  This indicates that Xdebug is ready and waiting to detect a script being run on the appropriate port.

 

2. Ensure that the installed WampServer is running.  If not running WampServer, ensure that the Apache server and PHP scripting engine are running.  The PHP script must be executed to be detected and parsed for debugging.

 

3. For debugging scripts through a browser, please add the URL variable 'XDEBUG_SESSION_START=<name>', e.g.:

 

http://localhost/test.php?XDEBUG_SESSION_START=myPHPTest

 

If you prefer not to append ?XDEBUG_SESSION_START=myPHPTest to all scripts to enable debugging when executed, you can set a flag in your php.ini file to enable debugging of every PHP script when run.  If you've installed WampServer, the easiest way to do this is to access the php.ini file through the WampServer menu:

 

 

Where Xdebug settings were defined during installation, if the remote_autostart option is set to "1" rather than "0":

 

xdebug.remote_autostart = 1

 

then every time a PHP file is executed after Build -> Start Debugger has been selected, Xdebug would detect and debug the running script.  Please note that the PHP script must be saved to the proper directory for the Apache server installed on your system in order to be run from "http://localhost/".  With the default WampServer installation, this would be under:

 

C:wampwww

 

When the URL is appropriately entered into your browser with the appended debug flag, the status bar in UEStudio should change to indicate that Xdebug detected the running script and has begun to debug it.  UEStudio will indicate this by displaying:

 

Xdebug: Initializing session

 

in the status bar.  Xdebug will process the script and update this prompt to:

 

Xdebug: Step Into

 

At this point, the debugging results will be displayed in the output window in UEStudio.  You will either see an error message displayed, or the output window will indicate "No debug message." which indicates that no errors were found in the debugged script.  If this debugged file is not already open in UEStudio, it will automatically be opened at this point in time.  If no errors exist in the script, the debugger focus arrow will be displayed on the first line of the script:

 

 

If an error is found, the line associated with the error displayed in the output window will be marked by the debugger focus arrow.

 

Command Line PHP Debugging

An environment variable must be defined before debugging of command line PHP scripts can occur.  The environment variable name should be "XDEBUG_CONFIG" and the value should be "idekey=<session_name>" where <session_name> can be any value, e.g. "idekey=phpdebug".

 

 

1. In the Build menu select Start Debugger to initiate the Xdebug debugging session.  When Xdebug is invoked a dialog will appear:

 

 

At this point you may press "OK" and proceed as indicated in the dialog:

 

2. After pressing "OK" in the Listening for Connection... dialog, you will see

 

Xdebug: Listening for connection...

 

in the status bar.  This indicates that Xdebug is ready and waiting to detect a script being run on the appropriate port.

 

3. Open a command prompt and execute the script to be debugged, e.g.:

  

  C:>php c:php_modules est.php

  

 Unlike browser-based scripts, no debug flag is required for command line scripts because this is automatically handled by the environment variable already defined.

 

4. When the script has been executed, the status bar in UEStudio should change to indicate that Xdebug detected the running script and has begun to debug it.  UEStudio will indicate this by displaying:

 

Xdebug: Initializing session

 

in the status bar.  Xdebug will process the script and update this prompt to:

 

Xdebug: Step Into

 

At this point, the debugging results will be displayed in the output window in UEStudio.  You will either see an error message displayed, or the output window will indicate "No debug message." which indicates that no errors were found in the debugged script.  If this debugged file is not already open in UEStudio, it will automatically be opened at this point in time.  If no errors exist in the script, the debugger focus arrow will be displayed on the first line of the script:

 

 

If an error is found, the line associated with the error displayed in the output window will be marked by the debugger focus arrow.

 

Attachments
There are no attachments for this article.
Related Articles
Registering UltraEdit/UEStudio
Viewed 14710 times since Thu, Oct 13, 2011
Title Bar
Viewed 3157 times since Thu, Oct 20, 2011
Large File Handling
Viewed 4001 times since Thu, Oct 20, 2011
Selecting Text
Viewed 3398 times since Thu, Oct 20, 2011
Drag and Drop Files
Viewed 3378 times since Thu, Oct 13, 2011
Cursor Arrows (Cursor Movement)
Viewed 2725 times since Thu, Oct 13, 2011
Home and End keys (Cursor Movement)
Viewed 3044 times since Thu, Oct 13, 2011
Tab Indentation
Viewed 3094 times since Thu, Oct 13, 2011
Command Line Parameters
Viewed 15288 times since Thu, Oct 13, 2011
Code Folding
Viewed 2466 times since Thu, Oct 13, 2011