PHP extension Xdebug installation and use instance

Source: Internet
Author: User
Tags php debugger

What is Xdebug? It is a tool that can be used to debug php code and run it. The following small series will introduce you to the Xdebug installation method. The following tutorial is based on linux and windows systems.

Q: What is xdebug?

A: xdebug is an open-source php debugger that is loaded and used as A php module.

Last week, I found that xdebug has release of RC (release candidate) Version 2, so I took it and installed it. By the way, I wrote an installation manual, hoping to help you.

Install the linux xdebug module and related tools:

Test environment: Ubuntu12.04 + PHP 5.3.10

The Code is as follows: Copy code

# Obtain the latest xdebug source code package
Git clone git: // github.com/derickr/xdebug.git
Cd xdebug/
# If the phpize extension is not installed, try: apt-get install phpize
Phpize
./Configure -- enable-xdebug
Make & make install

The path generated here is/usr/lib/php5/20090626 + lfs/xdebug. so.
Then change the php. ini file.
Add these configuration options

The Code is as follows: Copy code

[Xdebug]
; Extension file path
Zend_extension =/usr/lib/php5/20090626 + lfs/xdebug. so
 
; Enable Automatic Tracking
Xdebug. auto_trace = On
; Enable exception tracking
Xdebug. show_exception_trace = On
; Enable Automatic Start of remote debugging
Xdebug. remote_autostart = On
; Enable remote debugging
Xdebug. remote_enable = On
; Collect Variables
Xdebug. collect_vars = On
; Collect return values
Xdebug. collect_return = On
; Collect Parameters
Xdebug. collect_params = On
; Trace format
Xdebug. trace_format = 0
; Output Folder
Xdebug. trace_output_dir =/tmp/xdebug
; Output file name format
Xdebug. trace_output_name = trace. % c. % p
; Enable Analyzer
Xdebug. profiler_enable = On
; Output path
Xdebug. profiler_output_dir =/tmp/xdebug
; Output file name format
Xdebug. profiler_output_name = cachegrind. out. % p
; Records memory usage
Xdebug. show_mem_delta = On

After configuration, you can use php-I | grep xdebug to query the configured value.


Windows xdebug module Installation


1, go to www.xdebug.org to download the corresponding version of php module files, save the downloaded files to the php ext directory, you can modify the file name, such as saved to: xdebug-2.0.0RC1.dll
2. Modify php. ini and add the following information:

The Code is as follows: Copy code

[Xdebug]
Zend_extension_ts = "c:/php5/ext/xdebug-2.0.0RC1.dll"
Xdebug. auto_trace = on
Xdebug. collect_params = on
Xdebug. collect_return = on
Xdebug. trace_output_dir = "c:/Temp/xdebug"
Xdebug. profiler_enable = on
Xdebug. profiler_output_dir = "c:/Temp/xdebug"

Parameter description:
Zend_extension_ts = "c:/php5/ext/xdebug-2.0.0RC1.dll"
Load the xdebug module. Here it cannot be loaded in the way of extension = xdebug-2.0.0RC1.dll, it must be loaded in the way of zend, otherwise after installation, the xdebug section printed by phpinfo contains the warning message of Must loaded as zend extension (unknown cause ).

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 = "c:/Temp/xdebug"
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 = "c:/Temp/xdebug ";
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

3. Restart apache

In this way, when running php locally, some debugging information files will be generated in the Set directory:

The file name format of the function call process monitoring information file is 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.
File Name format of the performance monitoring file: cachegrind. out. ×××××××.
This file can also be viewed directly, but the information format is not easily understood by humans,
So we need the next software.
Ii. Install wincachegrind
Because the content of the performance monitoring file cachegrind. out. ×××××××× is not easily understood by humans, we need a tool to read it. Windows has such a software: wincachegrind.
1. Go to http://sourceforge.net/projects/wincachegrind/download and install wincachegrind
2. After installing and running the tool, Click Tools> options to set the value of xdebug. profiler_output_dir in your working folder (php. ini)
In this way, you can intuitively view the information of the performance monitoring file.

In addition, I do not know which parameter is not set correctly. All the monitoring information of function call processes after php running on my machine is written to a trace. ××××××. in xt, if anyone knows it, give it a clear path.

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.