Use xdebug to Debug PHP to find the PHP program bottleneck _ PHP Tutorial

Source: Internet
Author: User
Tags apache error log
Use xdebug to Debug PHP to find out the bottleneck of the PHP program. Xdebug is an extension application of PHP. with xdebug, you can easily debug the PHP program. with it, we don't need to use var_dump (), print_r () and so on. Xd XdebugIt is an extension application of PHP. with xdebug, you can easily debug the PHP program. with it, we don't need to use it. var_dump(), print_r()And so on.
Xdebug provides more functions to Debug PHP scripts comprehensively. XdebugThe main functions are as follows:

  1. Stack tracing and function tracing;
  2. Error message;
  3. Memory allocation;
  4. Analyzes the php script information;
  5. Code coverage analysis;
  6. Remote debugging analysis;
1. set up an xdebug debugging environment on Ubuntu to install the Xdebug module.

Use apt-get to install xdebug on the terminal. the command is as follows:

Sudo apt-get install php5-dev for php-pear
Sudo apt-get install php5-xdebug

Open the php. ini file (for example, gedit/etc/php5/apache2/php. ini ). Configure as follows;

; Load the xdebug dynamic link library
Extension = xdebug. so
Xdebug analysis file output path
Xdebug. profiler_output_dir = "/var/www/xdebug /"
The analyzer is disabled by default. when debugging, add XDEBUG_PROFILE = true to the url.
Xdebug. profiler_enable = Off
Xdebug. profiler_enable_trigger = 1

Restart apache to Debug PHP using xdebug.

2. install xdebug in windows

Take PHP5.1.4 and Windows as an example (for other PHP versions, see the official website for other platforms ):
1. log on to www.xdebug.org, there is a Windows modules on the right side of the home page, select PHP5.1.2 +, download the php_xdebug-5.1.2-2.0.0beta6.dll file;
2. put the downloaded php_xdebug-5.1.2-2.0.0beta6.dll in the C: php5ext directory and rename it php_xdebug.dll;
3. edit php. ini and add the following lines:

Extension = php_xdebug.dll
[Xdebug]
Xdebug. profiler_enable = on
Xdebug. trace_output_dir = "I: Projectsxdebug"
Xdebug. profiler_output_dir = "I: Projectsxdebug"
Xdebug. dump. GET = *
Xdebug. show_local_vars = 1

For more information about the parameters of PHP. ini, see annotations in ubuntu.

3. use xdebug for PHP Debugging. the xdebug debugging variable is more friendly.

Xdebug overwrites phpvar_dump()Function.
The var_dump () in xdebug gives variable objects different colors, display type length, and control the display level. the display mode is formatted and clear and friendly.
You need to use this function. pay attention to the following parameters.

; Overwrite the var_dump () function in php; enabled by default; value: 1; 0; disabled;
Xdebug. overload_var_dump = 1
; Controls the display size of array sub-elements. the default value is 256.
Xdebug. var_display_max_children = 256
; Control the printing size of variables. the default value is 512.
Xdebug. var_display_max_data = 512
Controls the display level of arrays and object elements. The default value is 3.
Xdebug. var_display_max_depth = 3

Stack tracing function of xdebug

If the script contains errors such as incorrect function parameters, repeated methods, and syntax errors. Xdebug can trace the error generation process.

For more information about parameter configuration, see http://xdebug.com/docs/stack_trace.

4. use xdebug to test script performance

Configure php. ini as follows:

The default value is 0. the xdebug debugger is not enabled;
Xdebug. profiler_enable = 0
The default value is 0. here it is set to 1, which can be passed through the XDEBUG_PROFILE parameter through GET/POST.
Xdebug. profiler_enable_trigger = 1

Tool for viewing test performance results

After testing, we need to check the test results to find the PHP bottleneck.
Two viewing tools are recommended here, which can be used in ubuntu.KCachegrindWhich can be used in windowsWinCacheGrind. For details, see how to use the xdebug test result tool Google, which is very simple. You can understand it by understanding E.

5. xdebug usage notes and related parameter descriptions

If you do not see it in the output of phpinfo (),XdebugPart, Xdebug fails to load. The Apache error log lists the causes. Common errors include path errors of zend_extension or conflicts with other extensions. For example, to use XCache and Xdebug, you must first load XCache. However, because Xdebug is suitable for development and assumes that the xdebug. so path is correct, you need to disable other extensions and try again. You can then re-enable the extension to perform other tests, such as the cache effect.

The Xdebug site also has some other troubleshooting skills.

Xdebug-related parameter settings xdebug. default_enable

Type: Boolean default value: On
If this parameter is set to On, the stack trace is displayed in the error event by default. You can use xdebug_disable () in the code to disable the display of stack trace. This is one of the basic functions of xdebug. it is wise to set this parameter to On.

For more information, click the next page!

  • 2 pages in total:
  • Previous Page
  • 1
  • 2
  • Next page

Http://www.bkjia.com/PHPjc/364700.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/364700.htmlTechArticlexdebug is a PHP extension application, with xdebug can easily debug the PHP program, with it, we do not need to use var_dump (), print_r () and so on. Xd...

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.