Xdebug文档(三)堆栈跟踪,xdebug文档堆栈跟踪_PHP教程

WBOY
Freigeben: 2016-07-12 08:50:25
Original
1170 Leute haben es durchsucht

Xdebug文档(三)堆栈跟踪,xdebug文档堆栈跟踪

当xdebug激活时,PHP一旦要显示通知、警告或错误时,xdebug 显示堆栈跟踪信息。这个堆栈信息能跟据你的需要来配置显示。

Xdebug显示的堆栈跟踪都是以保守数量状态显示信息。因为大量的信息处理和呈现会拖慢脚本执行。通过不同的设置对于显示更多详尽的信息提供了可能。

 

堆栈跟踪的变量

Xdebug一般会在堆栈跟踪时显示变量信息。在收集和显示情况下变量信息都会携带大量资源。尽管如此,很多情况下这些变量信息的显示是很有帮助的,这是为什么会有xdebug.clollect_params设置的原因。以下脚本,会在设置不同值情况下输出不同的信息:

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>?>
Nach dem Login kopieren

默认值:

( ! ) 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

1值:

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

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值:

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

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值:
Nach dem Login kopieren
ini_set('xdebug.collect_params', '4');
Nach dem Login kopieren

( ! ) 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

相关设置:

xdebug.cli_color

类型: integer, 默认值: 0, 始于 2.2版以上

设置为1时,xdebug会在CLI模式下且在tty终端输出时,会以有色显示var_dump跟踪输出的文字。window下, ANSICON工具需要安装。

设置为2时,则不管是否连接到tty终端或ANSICON是否被安装,xdebug会一直用颜色显示var_dump和调试跟踪信息。这种情形下,你可能在结束处看到转义码。

xdebug.collect_includes

类型: boolean, 默认值: 1

默认情况下xdebug将使用include(), include_once(), require() 或 require_once()方法引用的文件名写入到跟踪文件里。

xdebug.collect_params

类型: integer, 默认值: 0

默认为0时,该设置控制xdebug不管是函数追踪还是堆栈跟踪都会收集调用函数的参数。

默认0值是考虑到大规模脚本会占用大量内存,所以不会为了大脚本来运行它。你可以安全地打开此设置,但你会预料到会一些脚本上的问题像大量函数调用兼庞大的数据结构作为参数传递。Xdebug2不会有增加内存使用的问题,因为它不会存储到内存,而是只存入磁盘中。这只需要你有足够的磁盘使用量即可。

该设置有4种设置值。每种都会呈现不同的信息。以下表格展示各种设置值信息:

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版本新特性)

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>
Nach dem Login kopieren

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>
Nach dem Login kopieren

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>?>
Nach dem Login kopieren

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

 
Nach dem Login kopieren
Nach dem Login kopieren
 
Nach dem Login kopieren
Nach dem Login kopieren

掩码参数"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>?>
Nach dem Login kopieren

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

Example:

<?<span>php
xdebug_start_function_monitor( [ </span>'DramModel::canSee', 'Whisky->drink'<span>] );
</span>?>
Nach dem Login kopieren

 

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

 

void xdebug_stop_function_monitor()

停止函数监视

始于版本2.4

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

 

 

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133572.htmlTechArticleXdebug文档(三)堆栈跟踪,xdebug文档堆栈跟踪 当xdebug激活时,PHP一旦要显示通知、警告或错误时,xdebug 显示堆栈跟踪信息。这个堆栈信息...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!