Detailed explanation of PHP debugging and performance analysis tools Xdebug and php debugging xdebug

Source: Internet
Author: User

Detailed explanation of PHP debugging and performance analysis tools Xdebug and php debugging xdebug

During program development, the most commonly used debugging method is to print statements using echo, print_r (), var_dump (), and printf. The execution efficiency of PHP scripts, usually the script execution time. The efficiency of Database SQL is usually the database Query time, but this does not really locate and analyze the bottleneck of script execution and database Query? In this regard, there is a PHP program debugger called Xdebug (www.xdebug.org), which can be used to track, Debug, and analyze the running status of PHP programs.

1. Install this module on windows:

1. Download PHP XDebug extension, URL: http://xdebug.org/(this depends on your current PHP version );

2. Put the downloaded module (php_xdebug-2.0.5-5.2.dll) under the ext directory installed in PHP;

3. Configure the php. ini file and add the following lines

**************************************

Extension = php_xdebug-2.0.5-5.2.dll
[Xdebug]
Xdebug. profiler_enable = on
Xdebug. trace_output_dir = "E:/Projects/xdebug" # directory for storing data files output by Xdebug
Xdebug. profiler_output_dir = "E:/Projects/xdebug"
**************************************** ****************

4. Restart the Apache server. Done !!!

5. <? Php echo phpinfo ();?> If xdebug is displayed in the output, the installation and configuration are successful.

6. On Windows, you can use the client (Windows): WinCacheGrind to open these files. You can display the content more intuitively:

II. A brief introduction to the Linux platform:

1. Compile and install XDebug in Linux

[Root @ localhost src] # tar-xvf xdebug-2.0.5
[Root @ localhost xdebug-2.0.5] #/usr/local/php/bin/phpize
[Root @ localhost xdebug-2.0.5] #./configure -- enable-xdebug -- with-php-config =/usr/locar/php/bin/php-config
[Root @ localhost xdebug-2.0.5] # make
You can copy the generated xdebug. so to the path directory pointed to by extension_dir.

2. Configuration

Vi/usr/local/php/lib/php. ini modify php. ini, remove the PHP acceleration module, and add the following configuration information to support XDebug extension.
# Extension = vld. so // the module that outputs OPCODES
Extension = xdebug. so
[Xdebug]
Xdebug. profiler_enable = on
Xdebug. trace_output_dir = "/tmp/xdebug"
Xdebug. profiler_output_dir = "/tmp/xdebug"
Xdebug. profile_output_name = "script"

Note: You can also use the [root @ localhost xdebug-2.0.5] #/usr/local/php/bin/php-m to list all extension modules

3. Restart the WEB Server

[Root @ localhost xdebug-2.0.5] # service httpd restart OK !!!

The Xdebug tool writes the tracked error information to the output data file in the form of a diary, which can be viewed by the file, but for the sake of being more intuitive, there is also a graphical tool to analyze the tracking diary records. WinCacheGrind (wincachegrind.souceforge.net) can be directly installed. From the graphic window, you can view the entire program structure, the number of calls of each function, and the execution time. Very professional and convenient !!!

Summary:Xdebug can 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.

The above explanation of PHP debugging and Performance Analysis Tool Xdebug is all the content that I have shared with you. I hope to give you a reference and support for the help house.

Related Article

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.