PHP Debugging and performance analysis tools Xdebug detailed

Source: Internet
Author: User
The following small series for everyone to bring a PHP debugging and performance analysis tools Xdebug detailed. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.

In the process of program development, the most commonly used debugging method is to use Echo, Print_r (), Var_dump (), printf () and so on to print the statement. The efficiency of the execution of a PHP script is usually the execution time of the script. 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. For this, there is a PHP program called Xdebug (www.xdebug.org) Debugger (a debug tool) that can be used to track, debug and analyze the health of PHP programs.

First, the installation of this module on the Windows platform to make a simple introduction:

1. Download php xdebug extension, url: http://xdebug.org/(This depends on the PHP version you currently use);

2. Place the downloaded module (php_xdebug-2.0.5-5.2.dll) in the ext directory of the PHP installation;

3. Configure the php.ini file to 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" #放置Xdebug输出的数据文件的目录
Xdebug.profiler_output_dir= "E:/projects/xdebug"
********************************************************

4. Restart the Apache server. Complete!!!

5. <?php echo phpinfo ();? > If you see Xdebug in the output content, the installation configuration is successful.

6. Under the Windows platform, you can use the client (Windows): Wincachegrind wincachegrind This software to open these files. You can display the content more visually:

Second, the Linux platform for a simple introduction:


1. Compile and install Xdebug under 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 that Extension_dir points to.

2. Configuration

Vi/usr/local/php/lib/php.ini Modify the php.ini, remove the PHP accelerator module, add the following configuration information to support the Xdebug extension
#extension =vld.so//is the module of the output 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 [root@localhost xdebug-2.0.5]#/usr/local/php/bin/php-m to list all expansion 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 journal, which can be viewed by the file, but for a more intuitive look, there is also a graphical interface tool to analyze the tracked journal records. Wincachegrind (wincachegrind.souceforge.net) This software is directly installed on the line, from the graphics window can be the entire program structure, the number of times each function is called, execution time is at a glance. Very professional very convenient!!!

Summary: Xdebug can track the operation of the program, through the analysis of log files, we can quickly find the program to run the bottleneck, improve program efficiency, thereby improving the overall system performance.

The above is the whole content of this article, I hope that everyone's study has helped.


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.