Installation and Use of phpXdebug

Source: Internet
Author: User
This article provides a detailed analysis of the installation and use of phpXdebug.

This article provides a detailed analysis of the installation and use of php Xdebug. For more information, see

Why Debugger?
Many PHP programmers use echo, print_r (), var_dump (), and printf () for debugging. In fact, this is enough for programmers with rich development experience, hong Kong servers are rented. During program execution, they can output the values of specific variables to determine whether the program execution is correct, even the efficiency can be seen (of course, some time functions may need to be used ). So why do we need a special debugging program to monitor our program running? The answer to this question may be later.
What is Xdebug?
Xdebug is an open-source PHP program debugger (a Debug tool) that can be used to track, Debug, and analyze the running status of PHP programs.
How to install Xdebug? :
1. Open and download the corresponding version
Win: Windows binaries version
Linux: source
Obtain a dll file (win) or run the Installation File (linux)
2. Installation
Win: Put the downloaded dll file in the corresponding directory. For example, put my files under D: \ xampp \ php \ ext;
Linux: run the Installation File
Tar-xvzf xdebug-2.1.2.tgz
Cd xdebug-2.1.2
Phpize (if phpize does not have this command, you need to install phpize once. Phpize allows php to support extension modules) install phpize: sudo apt-get install php5-dev
If the installation is complete, run the following command:
./Configure
Make
Make install
This interface is available.



Cp modules/xdebug. so/usr/lib/php5/20090626 + lfs move the xdebug. so file to php5
3. Edit php. ini and add the following lines to the Hong Kong Virtual Host:
[Xdebug]
Zend_extension = D: \ xampp \ php \ ext \ php_xdebug.dll (Win)
Zend_extension =/usr/lib/php5/20090626 + lfs/xdebug. so (Linux)

Xdebug. profiler_enable = on
Xdebug. trace_output_dir = "../Projects/xdebug"
Xdebug. profiler_output_dir = "../Projects/xdebug"
The directory "../Projects/xdebug" after you want to place the directory of the data file output by Xdebug. The Hong Kong server can be set freely.
4. Restart Apache;
5. Write a test. php file with the content If xdebug is displayed in the output, the installation and configuration are successful. For example:

Now let's start with the simplest program debugging step by step.Xdebug.
Debugging:
We first write a program that can cause execution errors, such as trying to contain a non-existent file.
TestXdebug. php
Require_once('Abc. php ');
?>
Then, we were surprised to find that the error information was colored:

However, apart from style changes, the error information we usually print is no different and does not make much sense. Okay. Let's rewrite the program:TestXdebug2.php
TestXdebug ();
FunctionTestXdebug (){
Require_once('Abc. php ');
}
?>
Output Information:

What have you found?XdebugTrace code execution and find the function with an errorTestXdebug ().
The code is more complex:
TestXdebug3.php

The Code is as follows:


TestXdebug ();
Function testXdebug (){
RequireFile ();
}
Function requireFile (){
Require_once ('abc. php ');
}
?>


Output Information:

That is to sayXdebugSimilarJavaOfExceptionTracking and backtracking can trace the specific error location step by step based on program execution. Even if the call in the program is complicated, we can also use this function to clarify the code relationship, quickly locate and troubleshoot problems.

PHP4.3.0Later versions andPHP5. This function isPHPThe Development TeamPHP5And then port it backPHP4.3.

, Xdebug

How do I detect deficiencies in the code?

[Xdebug]
Xdebug. profiler_enable = on
Xdebug. trace_output_dir = "I: \ Projects \ xdebug"
Xdebug. profiler_output_dir = "I: \ Projects \ xdebug"

The purpose of these lines is to write the execution analysis file"../Projects/xdebug"Directory (you can replace it with any directory you want to set ). If you open the corresponding directory after executing a program, you can find that a bunch of files are generated, suchCachegrind. out.1169585776Files named in this format. These areXdebugThe generated analysis file. Open it in the editor and you will see a lot of details about the program running,

Finally:

XdebugProvides a variety of built-in functions, andPHPThe function is overwritten to facilitate debugging and troubleshooting;XdebugWe can also track program running. By analyzing log files, we can quickly find the bottleneck of program running, improve program efficiency, and thus improve the performance of the entire system.

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.