How to debug PHP xdebug

Source: Internet
Author: User
Tags php debugger

PHP debugging has always been a problem for me. I have been using the echo and var_dump piling modes and the efficiency is very poor. This time I am determined to study how to debug PHP and write down the steps by the way, strengthen memory for your reference.

First, let's talk about how to use xdebug to debug PHP.Program.

My development environment:

1. Eclipse PDT (Eclipse IDE for PHP developers 1.3.0.20100617-0520). I like Eclipse IDE, Which is powerful and has many plug-ins.

2. XAMPP version 1.7.4 (APACHE 2.2.17, MySQL 5.5.8 (Community Server), PHP 5.3.5 (vc6 x86 32bit) + pear). XAMPP is very convenient to use and I am too lazy to configure it myself, in addition, I downloaded the zip version, mainly for Program Development and debugging.

3. xdebug, which is already included in the xampp php package. If you want to release it on your own, you can go to the xdebug website. However, note that xdebug requires the PHP version and compiler, and 32-bit or 64-bit

4. Windows 7

Configure PHP. ini

PHP. INI is located under XAMPP \ PHP \. First, edit this file, find the [xdebug] node, and remove the configuration annotation (here I use php5.3.5 of XAMPP, PHP. this node may not exist in ini ):

[Xdebug]
Zend_extension is the address of the php_xdebug.dl File
Zend_extension = ". \ ext \ php_xdebug.dll"

; Remote_enable allow xdebug to support debug Client
Xdebug. remote_enable = 1

Host address
Xdebug_remote_host = "localhost"

; Debug port
Xdebug. remote_port = 9000

; Debug Protocol
Xdebug. remote_handler = "dbgp"

In addition, it should be noted that the directory writing like "\ XAMPP \ PHP \ Ext" does not seem to be recognized in eclipse. I changed them to ". \ Ext" here"

 

Configure eclipse PDT

Add PHP executestables in Windows \ preferences, as shown in figure

Modify run \ debug configuration, select xdebug for PHP debugger, and select the one we just filled in for PHP executables. The php file is the file for debugging preparation:

 

Next, we will write a test program.

Add a PHP project in eclipse and add a simple PHP file, such as debug. php:

Debug. php

 
<? PHP
 
$ A = 1;
 
$ B = 2;
 
$ C = $ A + $ B;
 
Echo $ C;
 
?>

And write this file to the PHP file in debug confiugration. You can refer toConfigure eclipse PDT-> modify run \ debug Configuration.

Then debug, for example:

The above is the most basic PHP script debugging method, for your reference only. Note that the PHP script is debugged in the command line mode. I will explain in my blog how to debug PHP page files using web site.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.