PHP debugging tool Xdebug assembly Configuration tutorial

Source: Internet
Author: User
PHP debugging tool Xdebug installation and configuration tutorial describes PHP code debugging. for experienced PHPer, the echo, print_r, var_dump functions, or PHP development tools zendstudio and editplus can solve most of the problems, however, it is difficult for children's shoes to get started with PHP, and they only use the above PHP debugging tool Xdebug installation and configuration tutorial.

Speaking of PHP code debugging, for experienced PHPer, most problems can be solved through echo, print_r, var_dump functions, or PHP development tools zend studio and editplus, however, it is difficult for children's shoes to get started with PHP, and it is difficult to accurately detect PHP performance problems only through the above PHP debugging methods, xdebug is a very useful PHP debugging tool.
Xdebug, as a PHP debugging tool, provides a wide range of debugging functions. you can also configure Xdebug installation as zend studio and editplus to debug third-party PHP plug-ins. by enabling auto_trace) and analyzer function, you can intuitively see the performance data of PHP source code, in order to optimize PHP code. Today, I will share with you the basic knowledge of installing and configuring the PHP debugging tool Xdebug.

Xdebug installation tutorial

Download Xdebug ?????? Http://xdebug.org
First, we need to download Xdebug. Make sure to select the appropriate Xdebug version based on the installed PHP version. if you do not know the installed PHP version, you can refer to the phpinfo () function, xdebug also provides a phpinfo output information analysis tool to help you analyze how to install Xdebug. you only need to copy and submit the phpinfo output information. Address: Xdebug phpinfo Information Analysis address
Install Xdebug
Copy the downloaded php_xdebug-2.1.0-5.3-vc6.dll to the ext directory under the PHP installation directory, which is used to store the PHP Extension Library DLL file.

Configure php. ini
The last step to install Xdebug is to configure the php. ini file and add

[Xdebug]zend_extension="c:/php/ext/php_xdebug-2.1.0-5.3-vc6.dll"

Restart the Apache server and use the phpinfo () function.

PHP Xdebug configuration information

  Xdebug configuration prompt: Zend_extension_ts is used when Xdebug is configured in PHP5.3 or earlier versions. for PHP5.3 or later versions, zend_extension is used .?

  Reason why xdebug not loaded as zend extension information appears

The reason why xdebug not loaded as zend extension occurs is that when Xdebug is installed, we copy the Xdebug DLL file to the php \ ext directory, and it is easy to load Xdebug AS a php extension Library, in php. ini file added

extension=php_xdebug-2.1.0-5.3-vc6.dll?

This is an incorrect Xdebug installation method and must be loaded in zend mode.

Now the PHP Xdebug basic installation tutorial is complete. below we need to make some basic configuration for Xdebug.

XdebugAnalyzer functionConfiguration tutorial

After installing Xdebug, we also need to make basic configuration for Xdebug. by default, the PHP function auto-tracking (auto_trace) function and analyzer function of Xdebug are not enabled, which is required for debugging PHP code, some Xdebug configuration options are recommended to be enabled.

Before that, we need to create an Xdebug automatic tracking directory and a directory for storing the output file of the analyzer. make sure that the directory is read and written. here I am at D: the xdebug \ trace and xdebug \ profiler directories are created under \ PHPWeb.

Finally, complete the Xdebug configuration in the php. ini configuration file and find

[Xdebug]zend_extension="c:/php/ext/php_xdebug-2.1.0-5.3-vc6.dll"

? After that, add the Xdebug configuration information

xdebug.auto_trace=1xdebug.collect_params=1xdebug.collect_return=1xdebug.trace_output_dir="D:/PHPWeb/xdebug/trace"xdebug.profiler_enable=1xdebug.profiler_output_dir="D:/PHPWeb/xdebug/profiler"

? Finally, save php. ini and restart the Aapche server.

?

Execute the script using Xdebug

Use Xdebug_time_index () to display the time

Memory occupied by the test script:

Xdebug_memory_usage ()

Xdebug also provides an xdebug_peak_memory_usage () to view the peak memory usage.


Configuration options in Xdebug
Xdebug. auto_trace = 1
Whether to allow Xdebug to trace function calls. trace information is stored as files. the default value is 0.

Collect_params = 1
Whether to allow Xdebug to trace function parameters. the default value is 0.

Xdebug. collect_return = 1
Whether to allow Xdebug to trace function return values. the default value is 0.

Xdebug. profiler_enable = 1
Open the xdebug performance analyzer and store it as a file. this configuration cannot be configured using the ini_set () function. the default value is 0.

Xdebug. profiler_output_dir
Storage location of performance analysis files; default value:/tmp

Xdebug. profiler_output_name
Naming rules for performance analysis files. the default value is cachegrind. out. % p.

Xdebug. trace_output_dir
Directory of the output file of the function call trace information. the default value is/tmp.

Xdebug. trace_output_name
Naming rules for output file of function call trace information. the default value is trace. % c.


Note: The Xdebug trace and profiler output file name rules can be changed. for example, it is very convenient to name the file name as the PHP execution file name, process ID, and random number of the specific trail, for more instructions on Xdebug configuration options, refer to the instructions on Xdebug configuration options on the official website.
Now, the installation and configuration of Xdebug in the Xdebug tutorial of PHP debugging tool is complete. in the future, we will introduce how to configure and use Xdebug in zend studio and editplus.

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.