Home > Backend Development > PHP Tutorial > Xdebug document (3) stack trace, xdebug document stack trace_PHP tutorial

Xdebug document (3) stack trace, xdebug document stack trace_PHP tutorial

WBOY
Release: 2016-07-12 08:50:25
Original
1240 people have browsed it

The stack information displayed can be configured according to your needs.

The stack traces displayed by Xdebug all display information in a conservative quantitative state. Because large amounts of information processing and presentation can slow down script execution. Different settings provide the possibility to display more detailed information.

Stack trace variables

Xdebug generally displays variable information in stack traces. Variable information carries a lot of resources both in collection and display situations. Nonetheless, in many cases the display of information about these variables is helpful, which is why the xdebug.clollect_params setting is present. The following script will output different information when setting different values:

The script

<?<span>php
</span><span>function</span> foo( <span>$a</span><span> ) {
    </span><span>for</span> (<span>$i</span> = 1; <span>$i</span> < <span>$a</span>['foo']; <span>$i</span>++<span>) {
        </span><span>if</span> (<span>$i</span> == 500000<span>) xdebug_break();
    }
}

</span><span>set_time_limit</span>(1<span>);
</span><span>$c</span> = <span>new</span><span> stdClass;
</span><span>$c</span>->bar = 100<span>;
</span><span>$a</span> = <span>array</span><span>(
    </span>42 => <span>false</span>, 'foo' => 912124,
    <span>$c</span>, <span>new</span> stdClass, <span>fopen</span>( '/etc/passwd', 'r'<span> )
);
foo( </span><span>$a</span><span> );
</span>?>
Copy after login
Default value:

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 34< /em>

Call Stack

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 34

Call Stack

#

Time

Memory

Function

Location

1

0.0001

58564

{main}( )

../stack.php:0

2

0.0004

62764

foo( )

../stack.php:47

#

Time

Memory

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31

Call Stack

#

Time

Memory

Function

Location

1

0.0001

58132

{main}( )

../stack.php:0

2

0.0004

62380

foo( array(5) )

../stack.php:47

Function

Location

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31

Call Stack

#

Time

Memory

Function

Location

1

0.0001

58564

{main}( )

../stack.php:0

2

0.0004

62812

foo( array(5) )

../stack.php:47

1<🎜>
<🎜>0.0001<🎜> <🎜>58564<🎜> <🎜>{main}( )<🎜> <🎜>../stack.php:0<🎜>
<🎜>2<🎜> <🎜>0.0004<🎜> <🎜>62764<🎜> <🎜>foo( )<🎜> <🎜>../stack.php:47<🎜>
<🎜>1 value: <🎜> <🎜>ini_set('xdebug.collect_params', '1');<🎜>
<🎜>( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31< /em><🎜>
<🎜>Call Stack<🎜>

#<🎜>

<🎜>Time<🎜> <🎜>Memory<🎜> <🎜>Function<🎜> <🎜>Location<🎜>
<🎜>1<🎜> <🎜>0.0001<🎜> <🎜>58132<🎜> <🎜>{main}( )<🎜> <🎜>../stack.php:0<🎜>
<🎜>2<🎜> <🎜>0.0004<🎜> <🎜>62380<🎜> <🎜>foo( array(5) )<🎜> <🎜>../stack.php:47<🎜>
<🎜>2 value: <🎜> <🎜>ini_set('xdebug.collect_params', '2');<🎜>
<🎜>( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31< /em><🎜>
<🎜>Call Stack<🎜>

#<🎜>

<🎜>Time<🎜> <🎜>Memory<🎜> <🎜>Function<🎜> <🎜>Location<🎜>
<🎜>1<🎜> <🎜>0.0001<🎜> <🎜>58564<🎜> <🎜>{main}( )<🎜> <🎜>../stack.php:0<🎜>
<🎜>2<🎜> <🎜>0.0004<🎜> <🎜>62812<🎜> <🎜>foo( array(5) )<🎜> <🎜>../stack.php:47<🎜>

3值:

ini_set('xdebug.collect_params', '3');

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31

Call Stack

#

Time

Memory

Function

Location

1

0.0001

58564

{main}( )

../stack.php:0

2

0.0004

62812

foo( array (42 => FALSE, 'foo' => 912124, 43 => class stdClass { public $bar = 100 }, 44 => class stdClass { }, 45 => resource(2) of type (stream)) )

../stack.php:47

<br />4值:
Copy after login
ini_set('xdebug.collect_params', '4');
Copy after login

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31

Call Stack

#

Time

Memory

Function

Location

1

0.0001

58132

{main}( )

../stack.php:0

2

0.0004

62380

foo( $a = array (42 => FALSE, 'foo' => 912124, 43 => class stdClass { public $bar = 100 }, 44 => class stdClass { }, 45 => resource(2) of type (stream)) )

../stack.php:47

Related settings:

xdebug.cli_color

Type: integer, default value: 0, starting from version 2.2 or above

When set to 1, xdebug will display the text output by var_dump trace in color when outputting in CLI mode and tty terminal. Under window, the ANSICON tool needs to be installed.

When set to 2, xdebug will always display var_dump and debug trace information in color regardless of whether it is connected to a tty terminal or whether ANSICON is installed. In this case, you may see an escape code at the end.

xdebug.collect_includes

Type: boolean, Default value: 1

By default xdebug will write the file name referenced using include(), include_once(), require() or require_once() method to the trace file.

xdebug.collect_params

Type: integer, Default value: 0

When the default is 0, this setting controls xdebug to collect the parameters of the calling function regardless of function tracing or stack tracing.

The default value of 0 is to consider that large-scale scripts will take up a lot of memory, so it will not be run for large scripts. You can safely turn this setting on, but you can expect some scripting issues like lots of function calls and large data structures passed as arguments. Xdebug2 will not have the problem of increased memory usage because it does not store to memory, but only to disk. This just requires you to have enough disk usage.

This setting has 4 setting values. Each will present different information. The following table displays various setting value information:

Value

Argument Information Shown

0

无.

1

展示变量元素的值类型和值。

2

展示变量元素的值类型和值,并附带滑鼠提示显示完整信息。(CLI模式下不存在滑鼠提示)

3

完整变量内容(内容受限于以下设置: xdebug.var_display_max_children,xdebug.var_display_max_data and xdebug.var_display_max_depth.)

4

完整变量内容和名称。

5

PHP 序列化变量内容,不含名称。(2.3版本新特性)

Value<🎜><🎜>

<🎜>Argument Information Shown<🎜><🎜>

0<🎜>

<🎜>None.<🎜>

1<🎜>

<🎜>Shows the value type and value of the variable element. <🎜>

2<🎜>

<🎜>Displays the value type and value of variable elements, with mouse prompts showing complete information. (Mouse prompts do not exist in CLI mode) <🎜>

3<🎜>

<🎜>Full variable content (content is limited by the following settings: xdebug.var_display_max_children, xdebug.var_display_max_data and xdebug.var_display_max_depth.) <🎜>

4<🎜>

<🎜>Full variable content and name. <🎜>

5<🎜>

<🎜>PHP serializes variable content without name. <🎜>(2.3<🎜><🎜>New features in version<🎜><🎜>)<🎜><🎜>

xdebug.collect_vars

类型: boolean, 默认值: 0

该设置会让xdebug在一定范围内去收集变量信息。而这种分析工作相当慢因为xdebug会逆向解析PHP代码。该设置不会记录不同变量的值。如果你要利用xdebug_get_declared_vars()函数,那么就需要开启该设置了。

xdebug.dump.*

类型: string, 默认值: Empty

* 号可以用 COOKIE, FILES, GET, POST, REQUEST, SERVER, SESSION任意一个来代替. 这七个设置值控制在错误发生时的超全局变量的数据。

在php.ini中每个设置值都由逗号分隔形成变量列表,或者*号代表全部。要确定你在设置里没有空格。

为了在错误发生时收到REMOTE_ADDR 和 REQUEST_METHOD 信息和所有GET参数,可以设置:

xdebug.dump.SERVER = REMOTE_ADDR,REQUEST_METHOD

xdebug.dump.GET = *

xdebug.dump_globals

类型: boolean, 默认: 1

控制超全局变量值是否显示,无论在xdebug.dump.*设置了什么。

xdebug.dump_once

类型: boolean, 默认值: 1

控制是否在所有错误情况下显示超全局变量值(设为0值)或只在第一次出现(设为1值)。

xdebug.dump_undefined

类型: boolean, 默认值: 0

如果需要显示超全局变量中未定义值则该项设为1,否则保留0默认项。

xdebug.manual_url

类型: string, 默认值: http://www.php.net, 始于 Xdebug 2.2.1以下版本

指定函数追踪和错误信息的链接说明来源。建议设定使用最近的镜像链接。

xdebug.show_exception_trace

类型: integer, 默认值: 0

当设置为1时,Xdebug会在异常出现时甚至是该异常被捕捉也会显示其堆栈跟踪信息。

xdebug.show_local_vars

类型: integer, 默认值: 0

当设置为非0值时,Xdebug在错误情况下产生的堆栈跟踪会显示所有变量信息在最顶端范围。这有可能会产生大量信息,所以默认情况下关闭。

xdebug.show_mem_delta

Type: integer, Default value: 0

当该设置不为0时,xdebug的人类可读性追踪记录文件会显示函数调用时内存使用量。如果xdebug配值为产生机器可读性追踪文件,那么它们经常显示这些信息。、

xdebug.var_display_max_children

类型: integer, 默认值: 128

在使用 xdebug_var_dump(),xdebug.show_local_vars 或 追踪函数时,该设置控制数组元素和对象属性的数量显示。

若不受限制,可以设为-1值。

该设置不受Remot_Debuggin远程调试的任何影响。

xdebug.var_display_max_data

类型: integer, 默认值: 512

在使用 xdebug_var_dump(),xdebug.show_local_vars 或 追踪函数时,该设置控制字符串长度显示最大值。

若不受限制,可以设为-1值。

该设置不受Remot_Debugging远程调试的任何影响。

xdebug.var_display_max_depth

类型: integer, 默认值: 3

在使用 xdebug_var_dump(),xdebug.show_local_vars 或 追踪函数时,该设置控制数组元素和对象属性的显示层级。

最大值为1023,你可以设为-1表示其最大值。

该设置不受Remot_Debugging远程调试的任何影响。

相关函数:

array xdebug_get_declared_vars()

返回一个数组,数组元素都是当前范围内已定义的变量名。要使函数生效则xdebug.collect_vars必须开启。

Example:

<?<span>php
    </span><span>class</span><span> strings {
        </span><span>static</span> <span>function</span> fix_strings(<span>$a</span>, <span>$b</span><span>) {
            </span><span>foreach</span> (<span>$b</span> <span>as</span> <span>$item</span><span>) {
            }
            </span><span>var_dump</span><span>(xdebug_get_declared_vars());
        }
    }
    strings</span>::fix_strings(<span>array</span>(1,2,3), <span>array</span>(4,5,6<span>));
</span>?>
<span>/*</span><span>*
Returns:
array
  0 => string 'a' (length=1)
  1 => string 'b' (length=1)
  2 => string 'item' (length=4)
 
</span><span>*/</span>
Copy after login

PHP5.1之前版本,变量名“a”不会在返回的数组中,因为在xdebug_get_declared_vars()函数执行时,该变量没被使用。

array xdebug_get_function_stack()

返回一数组,内含在函数这个点显示出来的类似于堆栈跟踪的信息。

Example:

<?<span>php
    </span><span>class</span><span> strings {
        </span><span>function</span> fix_string(<span>$a</span><span>)
        {
            </span><span>var_dump</span><span>(xdebug_get_function_stack());
        }

        </span><span>function</span> fix_strings(<span>$b</span><span>) {
            </span><span>foreach</span> (<span>$b</span> <span>as</span> <span>$item</span><span>) {
                </span><span>$this</span>->fix_string(<span>$item</span><span>);
            }
        }
    }

    </span><span>$s</span> = <span>new</span><span> strings();
    </span><span>$ret</span> = <span>$s</span>->fix_strings(<span>array</span>('Derick'<span>));
</span>?>
<span>/*</span><span>*
Returns:

array

  0 => 

    array

      'function' => string '{main}' (length=6)

      'file' => string '/var/www/xdebug_get_function_stack.php' (length=63)

      'line' => int 0

      'params' => 

        array

          empty

  1 => 

    array

      'function' => string 'fix_strings' (length=11)

      'class' => string 'strings' (length=7)

      'file' => string '/var/www/xdebug_get_function_stack.php' (length=63)

      'line' => int 18

      'params' => 

        array

          'b' => string 'array (0 => 'Derick')' (length=21)

  2 => 

    array

      'function' => string 'fix_string' (length=10)

      'class' => string 'strings' (length=7)

      'file' => string '/var/www/xdebug_get_function_stack.php' (length=63)

      'line' => int 12

      'params' => 

        array

          'a' => string ''Derick'' (length=8)

 </span><span>*/</span>
Copy after login

integer xdebug_get_stack_depth()

返回堆栈深度层级。脚本主体为0级而各种引用或调用函数则添加一个堆栈深度层级。

none xdebug_print_function_stack( [ string message [, int options ] ] )

用类似在错误情况下显示当前函数追踪信息。

"message" 参数允许你可以自定义显示信息。 (始于Xdebug 2.1版本).

Example:

<?<span>php
</span><span>function</span> foo( <span>$far</span>, <span>$out</span><span> )
{
    xdebug_print_function_stack( </span>'Your own message'<span> );
}
foo( </span>42, 3141592654<span> );
</span>?>
Copy after login

Returns:

( ! ) Xdebug: Your own message in /home/httpd/html/test/xdebug/print_function_stack.php on line 5

Call Stack

#

Time

Memory

Function

Location

1

0.0006

653896

{main}( )

../print_function_stack.php:0

2

0.0007

654616

foo( 42, 3141592654 )

../print_function_stack.php:7

3

0.0007

654736

xdebug_print_function_stack ( 'Your own message' )

../print_function_stack.php:5

 
Copy after login
Copy after login
 
Copy after login
Copy after login

掩码参数"options" 允许你配置一些额外的参数选项。支持的选项有:

<strong>XDEBUG_STACK_NO_DESC</strong>

如果设置此项,则显示的追踪信息不包含头部。这对于你想从自定义的错误处理器中显示自己的错误追踪信息就很有用。除此之外,你可以在需要显示的位置调用xdebug_print_function_statck()函数。(始于xdebug2.3)

void xdebug_start_function_monitor( array $list_of_functions_to_monitor )

开始函数监控。

始于版本2.4

该函数在将一系列的函数名作为参数传递时就开始监视这些函数。函数监视器会找出这些你提供的函数所在的代码。这样可以用于追踪那些旧函数或废弃的函数。

Example:

<?<span>php
xdebug_start_function_monitor( [ </span>'strrev', 'array_push'<span> ] );
</span>?>
Copy after login

你也可以添加类方法或静态方法到数组中进行监视。例如,为了捕获静态调用DramModel::canSee 和 动态调用 Whisky->drink,你可以开始以下监视:

Example:

<?<span>php
xdebug_start_function_monitor( [ </span>'DramModel::canSee', 'Whisky->drink'<span>] );
</span>?>
Copy after login

 

被定义的函数要区分大小写,若动态调用到静态方法将不会被捕获。

 

void xdebug_stop_function_monitor()

停止函数监视

始于版本2.4

该函数停止对函数监视。需要获取被监视函数列表,可以使用xdebug_get_monitored_functions()函数。

 

 

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133572.htmlTechArticleXdebug文档(三)堆栈跟踪,xdebug文档堆栈跟踪 当xdebug激活时,PHP一旦要显示通知、警告或错误时,xdebug 显示堆栈跟踪信息。这个堆栈信息...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template