Home >Backend Development >PHP Tutorial >Detailed explanation of PHP XDebug configuration and installation method_PHP tutorial
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 | ||||
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.
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
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
|
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 |
|
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+ |
|
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 |
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 :
|
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] |
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: