PHP and xdebug usage Summary

Source: Internet
Author: User
Tags phpinfo zts
The combination of xdebug in PHP is a good combination for debugging in PHP. The following describes how to use xdebug in PHP:

1. Installation in Windows

Download Site http://www.xdebug.org/

Be sure to use a version that works with your PHP, such as 5 in xdebug. The 2 series version is 5.2

PHP with 5.3 series and PHP with 5.3. The current version is 2. 1. Then you will find

Two versions are available: thread-safe and non-secure. How can I know which version to download?

The source code of the web page displayed in phpinfo is copied

Http://www.xdebug.org/find-binary.php.

Which version should I download?

Put the downloaded file in the D: \ PHP \ ext directory and rename it php_xdebug.dll.

Then modify PHP. INI:

[Xdebug]

Zend_extension = "D: \ PHP \ ext \ php_xdebug.dll"

Xdebug. profiler_output_dir = "D: \ php53 \ xdebug"

Xdebug. profiler_enable = on

Xdebug. profiler_enable_trigger = 1

Xdebug. default_enable = on

Xdebug. show_exception_trace = on

Xdebug. show_local_vars = 1

Xdebug. max_nesting_level = 50

Xdebug. var_display_max_depth = 6

Xdebug. dump_once = on

Xdebug. dump_globals = on

Xdebug. dump_undefined = on

Xdebug. Dump. Request = *

Xdebug. Dump. Server = request_method, request_uri, http_user_agent

Xdebug. trace_output_dir = "D: \ php53 \ xdebug"

Note that you need to create an xdebug directory to put the debugging output file.

Restart Apache. You can see the xdebug section in phpinfo.

2 installation in Linux

Tar-xzf xdebug-2.0.0RC3.gz

CD xdebug-2.0.0RC3

/Usr/local/PHP/bin/phpize

./Configure -- enable-xdebug

CP modules/xdebug. So/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20020429/

 

Note:/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20020429/different PHP version paths are not necessarily placed in this path, you can specify xdebug in zend_extension_ts. so location.

3. You can write a simple program to see the effect, for example:

<? PHP

Testxdebug ();

Function testxdebug (){

Require_once ('abc. php ');

}

?>

After running, we can see that the error-related parts are output in the stack way like Java.

4. Analyze the output file under xdbebug

Because the files in this directory are difficult to understand, you can download tools to analyze them, for example:

Kcachegrind (for Linux), wincachegrind (for Windows), and webgrind (for Web pages ).

I'm using wincachegrind (http://sourceforge.net/projects/wincachegrind)

Then you can open the output file to view it.

5. Some xdebug configurations

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.

Xdebug. max_nesting_level

Type: integer; default value: 100

The value of this setting is the maximum level of nested functions that are allowed before the script will be aborted.

Limit infinite recursive access depth. The value of this parameter is the maximum access depth allowed by the nested program before the script fails.

Xdebug. dump_globals

Type: Boolean default value: 1

Restrict whether to display the value of the hyperglobal variable defined by xdebug. Dump. *.

For example, xdebug. dump. server = request_method, request_uri, http_user_agent prints the PHP hyper-global variables $ _ server ['request _ method'], $ _ server ['request _ URI '], and $ _ server ['HTTP _ user_agent'].

Xdebug. dump_once

Type: Boolean default value: 1

The value that limits whether the global variable is exceeded should be dumped in all error environments (when set to off) or just at the beginning (when set to on)

Xdebug. dump_undefined

Type: Boolean default value: 0

If you want to dump undefined values from the Super global variable, you should set this parameter to on; otherwise, it will be set to off.

Xdebug. show_exception_trace

Type: integer default value: 0

When this parameter is set to 1, xdebug enforces exception tracking even if an exception is caught.

Xdebug. show_local_vars

Type: integer default value: 0

When this parameter is set to not equal to 0, the stack dump generated by xdebug in the error environment will also display all local variables, including uninitialized variables at the top. Note that this will generate a large amount of information, so it is disabled by default.

Xdebug. profiler_append

Type: integer default value: 0

When this parameter is set to 1, the file will not be appended when a new requirement is sent to the same file (depending on the xdebug. profiler_output_name setting ). Otherwise, the file will be appended to a new file.

Xdebug. profiler_enable

Type: integer default value: 0

The permission to open the xdebug file is to create a file in the file output directory. These files can be read by kcachegrind to show your data. This setting cannot be set by calling ini_set () in your script.

Xdebug. profiler_output_dir

Type: String default value:/tmp

This file is written by the profiler file output. You are sure that the PHP user has the write permission on this directory. This setting cannot be set by calling ini_set () in your script.

Xdebug. profiler_output_name

Type: String default value: cachegrind. Out % P

This setting determines the name of the file written by the dump trace.

Remote debug

Related parameter settings

Xdebug. remote_autostart

Type: Boolean default value: 0

Generally, you need to use a clear http get/post variable to enable remote debug. When this parameter is set to on, xdebug often tries to enable a remote debug session and try to connect to the client, even if the get/post/cookie variable is not the current one.

Xdebug. remote_enable

Type: Boolean default value: 0

This switch controls whether xdebug should try to connect to a debug client that listens to the host and port according to xdebug. remote_host and xdebug. remote_port.

Xdebug. remote_host

Type: String default value: localhost

Select the host on which the debug client is running. You can use not only the host name but also the IP address.

Xdebug. remote_port

Type: integer; default value: 9000

This port is used by xdebug to connect to the remote host. 9000 is the default port between the client and the bound debug client. Many clients use this port number. It is best not to modify this setting.

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.