search
HomeBackend DevelopmentPHP TutorialXdebug document (3) stack trace, xdebug document stack trace_PHP tutorial

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>?>
Default value:

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

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

( ! ) 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.3New 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>

 

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>

 

 

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>?>

 

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

 
 

掩码参数"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>?>

 

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

Example:

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

 

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

 

void xdebug_stop_function_monitor()

停止函数监视

始于版本2.4

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

 

 

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133572.htmlTechArticleXdebug文档(三)堆栈跟踪,xdebug文档堆栈跟踪 当xdebug激活时,PHP一旦要显示通知、警告或错误时,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
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software