How to Debug PHP Program Remotely using phpDesigner 2008
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program thus making it behave as expected. PHP has an extension that allows us to debug PHP scripts in live manner, called Xdebug. This article explains how to use and configure Xdebug within phpDesigner IDE from MPSOFTWARE. Debugging with Xdebug allows the programmer to analyze, evaluate and find errors in the code line by line.
Configuration
In order to use Xdebug you must have PHP installed local on your computer configured with the Xdebug extesion.
By default, phpDesigner 2008 is installed with PHP and Xdebug configured otherwise please follow these steps:
- Download the latest PHP 5.x.x. package (not the installer) from http://www.php.net or use XAMPP for easier PHP, Apache, and MySQL installation
- Download the Xdebug extension for the PHP version you have installed in the previous step from http://www.xdebug.com. For example if you have PHP 5.2.1 installed, you need Xdebug 5.2.1
- Place the Xdebug extension in the extension folder where you installed PHP, for example c:\…\PHP\ext
- In the folder where you installed PHP, open php.ini. there is no such file, locate php.ini-dist and rename it to php.ini. If you are using XAMPP, the file is located on c:\xampp\php\php.ini or C:\xampp\apache\bin\php.ini
- Add the following line to php.ini in the [Zend] section:
zend_extension_ts = "./ext/php_xdebug.dll"
xdebug.remote_enable=on
xdebug.profiler_enable_trigger=on
Configure phpDesigner 2008 to know where to find the PHP interpreter (php.exe, win-php.exe or php-cgi.exe).
- On the Tools menu, point to Preferences
- Select Debugger
- In the field ‘PHP’ type in the path for the PHP interpreter (.exe), or click the Browse button to locate the PHP interpreter
Optionally if you run your apache web server on other port than 80, then you should set the Localhost section on the Debugger:
Set the Server path to localhost or any hostname that you want to debug on and the Port that the server is running on. The default value is 80.
Start Debugging Sessions
Before you can start a debug session, the Xdebug server must be started. You can start, restart or stop the Xdebug server on the Debug menu, select Xdebug IDE server.
Now you can begin debugging your script. Place a breakpoint on a script that you wish to debug. This is done by placing the cursor on the correct line on the file. Then select menu Debug – Toggle breakpoint or pressing F5 button on your keyboard. A red line will appear on the line.
Then, start a debug session from within the IDE or from the web browser and execute your script until the first breakpoint or error occurs. Select a main script file of your project, especially when you have a large project that consists of many files included in the main script file. This file is usually index.php. To start a debugging session, press F9 key. Your script will be suspended if there’s a line with breakpoint. From that line, you can:
- step to the next line by pressing F8 key
- step inside a function if the line with breakpoint is a function call by pressing F7
- continue running the program by pressing F9 key
When the execution is suspending, you can view the content and type of a variable by placing your mouse pointer over that variable.
You can also press F4 key that will start the debug session as in Run but will pause the execution until the line at cursor is reached. If any breakpoints or errors occurs before the line at cursor is reached the execution might be paused.
You may also press Shift-F8 key that will start the debug session as in Run but will pause when pressing the return key. If any breakpoints or errors occurs before the line at cursor is reached the execution might be paused.
To start a debug session from the web browser, execute the script you want to debug in the web browser. phpDesigner 2008 will break at the breakpoints you have set for that script or if any errors occours.
To trace the course of the executions in your script throughout the debugging session, use Call Stack panel. On the View menu, click Tool Panels and select Call stack.
To display the value of all global and local variables throughout the debugging session, use Variable panel. On the View menu, click Tool Panels and select Variables.
To monitor variables, objects, properties etc. throughout the debugging session use Watches panel. Monitored variables should start with a "$" (dollar sign). On the View menu, click Tool Panels and select Watches.
To evaluate and test expressions in your script use move the cursor upon variables to see their values. You can manipulate variables directly during a debugging session. Manipulated or injected variables will affect the value of the variable when the execution of the script continues. On the View menu, click Tool Panels and select Evaluation.
Messages that Xdebug sends to phpDesigner debug Log panel. On the View menu, click Tool Panels and select Log.
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=a4456060-c178-4796-9ae7-e01bd462686a)




Recent Comments