Home >Backend Development >PHP Tutorial >Detailed explanation of PHP XDebug configuration and installation method_PHP tutorial

Detailed explanation of PHP XDebug configuration and installation method_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:47:31929browse

XDebug is a debugging tool for PHP. We can use echo, print, etc. to call errors, but our functions cannot check the number of function executions and execution time. This can be achieved using XDebug. Let me introduce the configuration and installation process of php XDebug in winodws.

We first go to the official website to download php_xdebug.dll, 2. Place the downloaded php_xdebug.dll in the PHP installation directory phpext, and then edit the php.ini file

The code is as follows Copy code
 代码如下 复制代码

[xdebug]
zend_extension = "/home/ad/php/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"
xdebug.auto_trace = on
xdebug.auto_profile = on
xdebug.collect_params = on
xdebug.collect_return = on
xdebug.profiler_enable = on
xdebug.trace_output_dir = "/home/ad/xdebug_log"
xdebug.profiler_output_dir = "/home/ad/xdebug_log"

[xdebug]
zend_extension = "/home/ad/php/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"
xdebug.auto_trace = on
xdebug.auto_profile = on
xdebug.collect_params = on
xdebug.collect_return = on
xdebug.profiler_enable = on
xdebug.trace_output_dir = "/home/ad/xdebug_log"
xdebug.profiler_output_dir = "/home/ad/xdebug_log"

4. Restart Apache.
5. Write a test.php with the content of . If xdebug is seen in the output content, the installation and configuration are successful. Or go to /home/ad/xdebug_log to see if the log has come out.

Detailed explanation of PHP XDebug configuration and installation method_PHP tutorial

PHP Xdebug configuration information

Explanation of some Xdebug configuration options

xdebug.auto_trace = 1

Whether to allow Xdebug to trace function calls. The tracking information is stored in a file. The default value is 0

collect_params = 1

Whether to allow Xdebug to track function parameters, the default value is 0

xdebug.collect_return = 1

Whether to allow Xdebug to track function return values, the default value is 0

xdebug.profiler_enable = 1

Open the xdebug performance analyzer and store it in file form. This configuration cannot be configured with the ini_set() function. The default value is 0

xdebug.profiler_output_dir

The storage location of the performance analysis file. The default value is /tmp

xdebug.profiler_output_name

Naming rules for performance analysis files, the default value is cachegrind.out.%p

xdebug.trace_output_dir

Function call tracking information output file directory, the default value is /tmp

xdebug.trace_output_name

Function call trace information output file naming rules, the default is trace.%c

Setting Options

Category Setting Description

Log

xdebug.trace_output_dir

Log tracking output directory
xdebug.trace_output_name Log file name, xdebug provides a series of identifiers to generate file names in corresponding formats. For details, please refer to the official website
xdebug.trace_options How records are added to the file: 1 = Append (if the file exists). 0 (default) = Overwrite (if the file exists)
Show data xdebug.collect_params Non-zero value = Controls the parameter display options of the function
  • 0 = Do not display.
  • 1 = parameter type, value (for example: array(9)).
  • 2 = Same as 1, but slightly different in CLI mode
  • 3 = All variable contents
  • 4 = All variable contents and variable names (for example: array(0 => 9)).
xdebug.collect_return 1 = Display function return value. Default 0 does not display
xdebug.collect_vars 1 = Show which variables are used in the current scope and display the variable name. This option will not record the value of the variable. If necessary, use xdebug.collect_params
xdebug.collect_assignments 1 = Add a line to display variable assignment (if it is 1, it will be in the form $a = 1; this type of Assignment Expression will be displayed in the trace file)
Format xdebug.trace_format
  • 0 = human readable. Each column from left to right represents: time point, memory, memory difference (needs to set xdebug.show_mem_delta=1), level, function name, function parameters (needs to set, xdebug.collect_params= 1, as long as it is non-zero), the file name of the current code line, and the line number.
  • 1 = machine readable[1]. Need to use third-party app, such as: xdebug trace file parser or xdebug trace viewer
  • 2 = html format, that is, table, open with browser, display table
xdebug.show_mem_delta 1 = Display memory consumption (memory difference) of each function call
Behavior xdebug.auto_trace 1 = Turn on automatic tracking. (There are two tracking methods, one is automatic tracking, all php scripts will generate trace files when running; the other is triggered tracking, as follows)
xdebug.trace_enable_trigger[2]

1 = Use XDEBUG_TRACE GET/POST to trigger tracing, or set the cookie XDEBUG_TRACE. To avoid generating corresponding trace files for each request, you need to set auto_trace to 0

Note: This feature can only be set in version 2.2+

[xdebug-general] Re: Is trace_enable_trigger defunct?

Restrictions xdebug.var_display_max_depth Display depth of array and object elements: Mainly used when nesting arrays and object attributes to display several levels of element content. Default 3.
xdebug.var_display_max_data How long to display when the variable value is a string. Default 512.
xdebug.var_display_max_children The number of array and object elements displayed. Default 128

Some custom functions

Function Description
void xdebug_enable() 手动打开,相当于xdebug.default_enable=on
void var_dump() 覆写php提供的var_dump,出错时,显示函数堆栈信息,(前提:php.ini里html_errors为1),使用xdebug.overload_var_dump 设置是否覆写
void xdebug_start_trace( 
string trace_file_path 
[, integer options] )
手动控制需要追踪的代码段
trace_file_path :文件路径(相对或绝对,若为空).如果为空,或者不传参, 使用xdebug.trace_output_dir设置的目录
options :
  • XDEBUG_TRACE_APPEND: 1 = 追加文件内容末尾, 0 = 覆写该文件
  • XDEBUG_TRACE_COMPUTERIZED:
    • 2 =同 xdebug.trace_format=1 .
  • XDEBUG_TRACE_HTML: 4 = 输出HTML表格,浏览器打开为一table
void xdebug_stop_trace() 停止追踪,代码追踪在该行停止
string xdebug_get_tracefile_name() 获得输出文件名,与 xdebug.auto_trace配合使用.
void xdebug_var_dump([mixed var[,...]])  输出变量详细信息,相当于php里的var_dump,具体显示请看这里
xdebug.show_local_vars  默认为0,不显示;非零时,在php执行出错时,显示出错代码所在作用域所有本地变量(注:这会产生大量信息,因此默认是closed),具体显示差别如下图[3]
array xdebug_get_declared_vars() 显示当前作用域中已声明的变量
array xdebug_get_code_coverage() 显示某一段代码内,代码执行到哪些行[4]
Function Description void xdebug_enable() Open manually, equivalent to xdebug.default_enable=on

void var_dump() Overwrite the var_dump provided by php. When an error occurs, the function stack information is displayed (prerequisite: html_errors in php.ini is 1). Use xdebug.overload_var_dump to set whether to override void xdebug_start_trace( string trace_file_path [, integer options] ) Manually control the code segments that need to be traced
trace_file_path: file path (relative or absolute, if empty). If it is empty, or no parameters are passed, use the directory set by xdebug.trace_output_dir options:
  • XDEBUG_TRACE_APPEND: 1 = append to the end of the file content, 0 = overwrite the file
  • XDEBUG_TRACE_COMPUTERIZED:
    • 2 =Same as xdebug.trace_format=1.
  • XDEBUG_TRACE_HTML: 4 = Output an HTML table and open it as a table in the browser
void xdebug_stop_trace() Stop tracking, code tracking stops at this line string xdebug_get_tracefile_name() Get the output file name, used with xdebug.auto_trace. void xdebug_var_dump([mixed var[,...]]) Output variable details, equivalent to var_dump in php, please see here for specific display xdebug.show_local_vars The default is 0 and is not displayed; when it is non-zero, when an error occurs in PHP execution, all local variables in the scope of the error code are displayed (Note: This will generate a lot of information, so the default is closed). The specific display difference is as follows [ 3] array xdebug_get_declared_vars() Display declared variables in the current scope array xdebug_get_code_coverage() Show which lines of code are executed in a certain section of code[4] http://www.bkjia.com/PHPjc/632850.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632850.htmlTechArticleXDebug is a debugging tool for PHP. We can use echo, print, etc. to call errors, but Our functions have no way to check the number of function executions and execution time, but using XDebug...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn