Installation and configuration of php code debugging tool Xdebug in Windows and Linux _ PHP Tutorial

Source: Internet
Author: User
Install and configure the php code debugging tool Xdebug in Windows and Linux. I. Why do I need a Debugger? Many PHP programmers use echo, print_r (), var_dump (), and printf () for debugging. In fact, this is sufficient for programmers with rich development experience. I. Why do I need a 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, during program execution, they can output the values of specific variables to determine whether the program is correctly executed, 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.

2. 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.

III. install and configure XDebug in Windows

1. download XDebug binary: http://www.xdebug.org/download.php
Download the php version. for example:

The code is as follows:

5.2 http://www.xdebug.org/files/php_xdebug-2.1.2-5.2-vc6.dll
5.3 http://www.xdebug.org/files/php_xdebug-2.1.2-5.3-vc6.dll


2. find and open the php. ini file.
3. if ZendOptimizer has been configured, you need to first block configurations related to ZendOptimizer, which are generally as follows:

The code is as follows:

[Zend]
Zend_extension_manager.optimizer_ts = "path \ ZendOptimizer-3.3.0 \ lib \ Optimizer-3.3.0 ″
Zend_extension_ts = "path \ ZendOptimizer-3.3.0 \ lib \ ZendExtensionManager. dll"


Delete it or comment it out with a semicolon, as shown in the following code:

The code is as follows:

; [Zend]
; Zend_extension_manager.optimizer_ts = "path \ ZendOptimizer-3.3.0 \ lib \ Optimizer-3.3.0 ″
; Zend_extension_ts = "path \ ZendOptimizer-3.3.0 \ lib \ ZendExtensionManager. dll"


4. add the XDebug configuration. Refer to the following:

The code is as follows:

[Xdebug]
Zend_extension_ts = "path/xdebug/php_xdebug-2.1.2-5.2-vc6.dll"
Xdebug. auto_trace = on
Xdebug. trace_output_dir = "path \ xdebug"
Xdebug. profiler_enable = on
Xdebug. profiler_output_dir = "path \ xdebug"
Xdebug. collect_params = on
Xdebug. collect_return = on
Xdebug. remote_enable = on
Xdebug. remote_handler = dbgp
Xdebug. remote_host = localhost
Xdebug. remote_port = 9000

Note:
The above "path" must be changed to your local path.
Parameter description:

The code is as follows:


Zend_extension_ts = "c:/webserver/php5/ext/php_xdebug.dll"
Load the xdebug module. You cannot use the extension = php_xdebug.dll method to load the file. you must use the zend method to load the file. otherwise, phpinfo cannot display the xdebug item after installation.
Xdebug. auto_trace = on;
Automatically enable the "Monitor function call process" module. This function outputs the monitoring information of function calls in a file in the specified directory. The default value of this configuration item is off.
Xdebug. collect_params = on;
To enable the function of collecting "function parameters. Include the parameter values of function calls in the monitoring information of function process calls. The default value of this configuration item is off.
Xdebug. collect_return = on
; Enable the function to collect "function return values. Include the return value of a function in the monitoring information of function call. The default value of this configuration item is off.
Xdebug. trace_output_dir =
Set the path of the output file of the function call monitoring information.
Xdebug. profiler_enable = on
; Enable the Performance Monitor.
Xdebug. profiler_output_dir =
Set the path of the output file of performance monitoring information.

There are some more specific parameter settings, see: http://www.xdebug.org/docs-settings.php
5. restart the web server, such as Apache or IIS.
6. view the output of phpinfo. if the XDebug option is displayed, the configuration is successful.
7. view the debugging information file.
Running the php program locally will generate some debugging information files in the set Directory, including:
A. function call process monitoring information file, file name format: trace. ×××××. xt. This file can be viewed directly. it contains information such as the function running time, function call parameter value, return value, and file and location. The content format is relatively intuitive.
B. Performance Monitoring File. file name format: cachegrind. out. ×××××××.
This file can also be viewed directly, but the information format is not easily understood by humans. we can install the wincachegrind software to read it in a formatted manner. The download and installation methods are as follows:
Download: http://sourceforge.net/projects/wincachegrind/
Download and install and run the tool. then Click Tools> options to set the value of working folder (xdebug. profiler_output_dir in php. ini)
In this way, you can intuitively view the information of the performance monitoring file.

IV. install and configure XDebug in linux

In linux, you can download the source code for compilation and installation. the method is as follows.
1. download the source code for the corresponding php version source: http://www.xdebug.org/download.php
Example: xdebug-2.1.2.tgz version: http://www.xdebug.org/files/xdebug-2.1.2.tgz
2. Compile and install

The code is as follows:

Tar-xvzf xdebug-2.1.2.tgz
Cd xdebug-2.1.2
./Configure
Make
Make install


If phpize does not have this command, install it:

The code is as follows:

Sudo apt-get install php5-dev


3. move the xdebug. so file to php5

The code is as follows:

Cp modules/xdebug. so/usr/lib/php5/


4. edit php. ini and add the following lines:

The code is as follows:

[Xdebug]
Zend_extension =/usr/lib/php5/xdebug. so
Xdebug. profiler_enable = on
Xdebug. trace_output_dir = "../xdebug"
Xdebug. profiler_output_dir = "../xdebug"

5. restart Apache to test whether the installation is successful.

If xdebug is displayed in the output, the installation and configuration are successful.

Why? Many PHP programmers use echo, print_r (), var_dump (), and printf () for debugging. In fact, this is enough for programmers with rich development experience...

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.