Analyze PHP program bottlenecks using Xdebug in Ubuntu

Source: Internet
Author: User
There is a well-known 80-20 law in economics, which is referenced in programming, that is, 80% of the performance bottleneck is caused by 20% of the Code. With the XDebug extension of PHP in Ubuntu, You can effectively find the 20% code. 1. Install configuration 1. Download The XDebug extension of PHP at http://xdebug.org/2、to compile and install xdebugsudotarvxfxdebug-2.1.0.tgzcdxdebug-

There is a well-known 80-20 law in economics, which is referenced in programming, that is, 80% of the performance bottleneck is caused by 20% of the Code.

With the XDebug extension of PHP in Ubuntu, You can effectively find the 20% code.

I. installation and configuration

1. Download PHP XDebug extension, URL: http://xdebug.org/

2. Compile and install XDebug in Ubuntu

Sudo tar vxf xdebug-2.1.0.tgz cd xdebug-2.1.0.tgz

Sudo/usr/local/php/bin/phpize

Sudo./configure -- enable-xdebug -- with-php-config =/usr/local/php/bin/php-config

Sodu make & make install

Note: After installation is complete, there will be an xdebug. so file under/usr/local/php/lib/php/extension/no-debug-non-zts-20090626.

Sodu vim/usr/local/php/lib/php. ini

Modify php. ini and add the following configuration information to support XDebug extension.

Zend_extension =/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xdebug. so

[Xdebug]

Xdebug. auto_trace = On

Xdebug. collect_params = On

Xdebug. collect_return = On

Xdebug. trace_output_dir = "/tmp/xdebug"

Xdebug. profiler_enable = On

Xdebug. profiler_output_dir = "/tmp/xdebug"

Xdebug. profiler_output_name = "cachegrind. out. % c"

Modify folder permissions so that xdebug can write logs in the specified folder

Sudo mkdir-p/tmp/xdebug

Sudo chmod 777/tmp/xdebug

Sudo chown group: user/tmp/xdebug

Sudo/usr/local/apache/bin/apachectl-k restart

At this time, xdebug should have been configured successfully. You can use To view the php information. If the xdebug Column exists, the installation is successful.

At this time, every time you access the PHP file using a web browser, a log file with the corresponding timestamp will be generated and you can view the recorded information.

The log analysis software I use is WinCacheGrind. Because it is for windows, we need to start it with wine.

Next, enter WinCacheGrind to view the execution time of each function ~

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.