Documentation for: Xdebug 2

Xdebug doc 因为那个网站老是不能访问。晕倒。

 

Documentation for: Xdebug 2
? Installation

This section describes on how to install Xdebug.
? Basic Features

Xdebug's basic functions include the display of stack traces on error conditions, maximum nesting level protection and time tracking.
? Variable Display Features

Xdebug replaces PHP's var_dump() function for displaying variables. Xdebug's version includes different colors for different types and places limits on the amount of array elements/object properties, maximum depth and string lengths. There are a few other functions dealing with variable display as well.
? Stack Traces

When Xdebug is activated it will show a stack trace whenever PHP decides to show a notice, warning, error etc. The information that stack traces display, and the way how they are presented, can be configured to suit your needs.
? Function Traces

Xdebug allows you to log all function calls, including parameters and return values to a file in different formats.
? Code Coverage Analysis

Code coverage tells you which lines of script (or set of scripts) have been executed during a request. With this information you can for example find out how good your unit tests are.
? Profiling PHP Scripts

Xdebug's built-in profiler allows you to find bottlenecks in your script and visualize those with an external tool such as KCacheGrind or WinCacheGrind.
? Remote Debugging

Xdebug provides an interface for debugger clients that interact with running PHP scripts. This section explains how to set-up PHP and Xdebug to allow this, and introduces a few clients.
? FAQ

Frequently Asked Questions

<!-- MAIN FEATURE END -->  

 

Documentation for: Xdebug 2
» Feature: Basic Features

Xdebug's basic functions include the display of stack traces on error conditions, maximum nesting level protection and time tracking.



Related Settings


xdebug.default_enable
Type: boolean , Default value: 1
If this setting is 1, then stacktraces will be shown by default on an error event. You can disable showing stacktraces from your code with xdebug_disable() . As this is one of the basic functions of Xdebug, it is advisable to leave this setting set to 1.

xdebug.max_nesting_level
Type: integer , Default value: 100
Controls the protection mechanism for infinite recursion protection. The value of this setting is the maximum level of nested functions that are allowed before the script will be aborted.

xdebug.scream
Type: boolean , Default value: 0 , Introduced in Xdebug 2.1
If this setting is 1, then Xdebug will disable the @ (shut-up) operator so that notices, warnings and errors are no longer hidden.

Related Functions


string xdebug_call_class( )
Returns the calling class

This function returns the name of the class from which the current function/method was called from.

Example:

<?php
    
function  fix_string ( $a )
    {
        echo 
"Called @ " .
            
xdebug_call_file ().
            
":" .
            
xdebug_call_line ().
            
" from " .
            
xdebug_call_function ();
    }

    
$ret  fix_string (array( 'Derick' ));
?>

Returns:

Called @ /home/httpd/html/test/xdebug_caller.php:12 from {main}

string xdebug_call_file( )
Returns the calling file

This function returns the filename that contains the function/method that called the current function/method.

For an example see xdebug_call_class() .


string xdebug_call_function( )
Returns the calling function/method

This function returns the name of the function/method from which the current function/method was called from.

For an example see xdebug_call_class() .


int xdebug_call_line( )
Returns the calling line

This function returns the line number that contains the function/method that called the current function/method.

For an example see xdebug_call_class() .


void xdebug_disable( )
Disables stack traces

Disable showing stack traces on error conditions.


void xdebug_enable( )
Enables stack traces

Enable showing stack traces on error conditions.


array xdebug_get_headers( )
Returns all the headers as set by calls to PHP's header() function

Returns all the headers that are set with PHP's header() function, or any other header set internally within PHP (such as through setcookie()), as an array.

Example:

<?php
header
"X-Test" "Testing"  );
setcookie "TestCookie" "test-value"  );
var_dump xdebug_get_headers () );
?>

Returns:

array(2) {
  [0]=>
  string(6) "X-Test"
  [1]=>
  string(33) "Set-Cookie: TestCookie=test-value"
}

This function is introduced with Xdebug 2.1.


bool xdebug_is_enabled( )
Returns whether stack traces are enabled

Return whether stack traces would be shown in case of an error or not.


int xdebug_memory_usage( )
Returns the current memory usage

Returns the current amount of memory the script uses. Before PHP 5.2.1, this only works if PHP is compiled with --enable-memory-limit. From PHP 5.2.1 and later this function is always available.


int xdebug_peak_memory_usage( )
Returns the peak memory usage

Returns the maximum amount of memory the script used until now. Before PHP 5.2.1, this only works if PHP is compiled with --enable-memory-limit. From PHP 5.2.1 and later this function is always available.


float xdebug_time_index( )
Returns the current time index

Returns the current time index since the starting of the script in seconds.

Example:

<?php
echo  xdebug_time_index (),  "\n" ;
for (
$i  0 $i  250000 $i ++)
{
    
// do nothing
}
echo 
xdebug_time_index (),  "\n" ;
?>

Returns:

0.00038003921508789
0.76580691337585

<!-- MAIN FEATURE END -->
 

 

Documentation for: Xdebug 2
» Feature: Variable Display Features

Xdebug replaces PHP's var_dump() function for displaying variables. Xdebug's version includes different colors for different types and places limits on the amount of array elements/object properties, maximum depth and string lengths. There are a few other functions dealing with variable display as well.


Effect of settings on var_dump()

There is a number of settings that control the output of Xdebug's modified var_dump() function: xdebug.var_display_max_children , xdebug.var_display_max_data and xdebug.var_display_max_depth . The effect of these three settings is best shown with an example. The script below is run four time, each time with different settings. You can use the tabs to see the difference.

The script

<?php
class  test  {
    public 
$pub  false ;
    private 
$priv  true ;
    protected 
$prot  42 ;
}
$t  = new  test ;
$t -> pub  $t ;
$data  = array(
    
'one'  =>  'a somewhat long string!' ,
    
'two'  => array(
        
'two.one'  => array(
            
'two.one.zero'  =>  210 ,
            
'two.one.one'  => array(
                
'two.one.one.zero'  =>  3.141592564 ,
                
'two.one.one.one'   =>  2.7 ,
            ),
        ),
    ),
    
'three'  =>  $t ,
    
'four'  =>  range ( 0 5 ),
);
var_dump $data  );
?>

The results

array

  'one' =>
 
 'a somewhat long string!'
 (length=23)

  'two' =>
 
    array

      'two.one' =>
 
        array

          'two.one.zero' =>
 
 210

          'two.one.one' =>
 
            array

              ...
  'three' =>
 
    object
(test
)[1
]
      public
 'pub' =>
 
        &
object
(test
)[1
]
      private
 'priv' =>
 
 true

      protected
 'prot' =>
 
 42

  'four' =>
 
    array

      0 =>
 
 0

      1 =>
 
 1

      2 =>
 
 2

      3 =>
 
 3

      4 =>
 
 4

      5 =>
 
 5

array

  'one' =>
 
 'a somewhat long string!'
 (length=23)

  'two' =>
 
    array

      'two.one' =>
 
        array

          'two.one.zero' =>
 
 210

          'two.one.one' =>
 
            array

              ...
  more elements...

array

  'one' =>
 
 'a somewhat long '...
 (length=23)

  'two' =>
 
    array

      'two.one' =>
 
        array

          'two.one.zero' =>
 
 210

          'two.one.one' =>
 
            array

              ...
  'three' =>
 
    object
(test
)[1
]
      public
 'pub' =>
 
        &
object
(test
)[1
]
      private
 'priv' =>
 
 true

      protected
 'prot' =>
 
 42

  'four' =>
 
    array

      0 =>
 
 0

      1 =>
 
 1

      2 =>
 
 2

      3 =>
 
 3

      4 =>
 
 4

      5 =>
 
 5

array

  'one' =>
 
 'a somewhat long string!'
 (length=23)

  'two' =>
 
    array

      'two.one' =>
 
        array

          ...
  'three' =>
 
    object
(test
)[1
]
      public
 'pub' =>
 
        &
object
(test
)[1
]
      private
 'priv' =>
 
 true

      protected
 'prot' =>
 
 42

  'four' =>
 
    array

      0 =>
 
 0

      1 =>
 
 1

      2 =>
 
 2

      3 =>
 
 3

      4 =>
 
 4

      5 =>
 
 5

array

  'one' =>
 
 'a somewh'...
 (length=23)

  'two' =>
 
    array

      ...
  'three' =>
 
    object
(test
)[1
]
      ...
  more elements...


Related Settings


xdebug.overload_var_dump
Type: boolean , Default value: 1 , Introduced in Xdebug 2.1
By default Xdebug overloads var_dump() with its own improved version for displaying variables when the html_errors php.ini setting is set to 1. In case you do not want that, you can set this setting to 0, but check first if it's not smarter to turn off html_errors.

xdebug.var_display_max_children
Type: integer , Default value: 128
Controls the amount of array children and object's properties are shown when variables are displayed with either xdebug_var_dump() , xdebug.show_local_vars or through Function Traces . This setting does not have any influence on the number of children that is send to the client through the Remote Debugging feature.

xdebug.var_display_max_data
Type: integer , Default value: 512
Controls the maximum string length that is shown when variables are displayed with either xdebug_var_dump() , xdebug.show_local_vars or through Function Traces . This setting does not have any influence on the amount of data that is send to the client through the Remote Debugging feature.

xdebug.var_display_max_depth
Type: integer , Default value: 3
Controls how many nested levels of array elements and object properties are when variables are displayed with either xdebug_var_dump() , xdebug.show_local_vars or through Function Traces . This setting does not have any influence on the depth of children that is send to the client through the Remote Debugging feature.

Related Functions


void var_dump( [mixed var [, ...]] )
Displays detailed information about a variable

This function is overloaded by Xdebug, see the description for xdebug_var_dump() .


void xdebug_debug_zval( [string varname [, ...]] )
Displays information about a variable

This function displays structured information about one or more variables that includes its type, value and refcount information. Arrays are explored recursively with values. This function is implemented differently from PHP's debug_zval_dump() function in order to work around the problems that that function has because the variable itself is actually passed to the function. Xdebug's version is better as it uses the variable name to lookup the variable in the internal symbol table and accesses all the properties directly without having to deal with actually passing a variable to a function. The result is that the information that this function returns is much more accurate than PHP's own function for showing zval information.

Example:

<?php
    $a 
= array( 1 2 3 );
    
$b  =&  $a ;
    
$c  =&  $a [ 2 ];

    
xdebug_debug_zval ( 'a' );
?>

Returns:

a: (refcount=2, is_ref=1)=array (
	0 => (refcount=1, is_ref=0)=1, 
	1 => (refcount=1, is_ref=0)=2, 
	2 => (refcount=2, is_ref=1)=3)


void xdebug_debug_zval_stdout( [string varname [, ...]] )
Returns information about variables to stdout.

This function displays structured information about one or more variables that includes its type, value and refcount information. Arrays are explored recursively with values. The difference with xdebug_debug_zval() is that the information is not displayed through a web server API layer, but directly shown on stdout (so that when you run it with apache in single process mode it ends up on the console).

Example:

<?php
    $a 
= array( 1 2 3 );
    
$b  =&  $a ;
    
$c  =&  $a [ 2 ];

    
xdebug_debug_zval_stdout ( 'a' );

Returns:

a: (refcount=2, is_ref=1)=array (
	0 => (refcount=1, is_ref=0)=1, 
	1 => (refcount=1, is_ref=0)=2, 
	2 => (refcount=2, is_ref=1)=3)

void xdebug_dump_superglobals( )
Displays information about super globals

This function dumps the values of the elements of the super globals as specified with the xdebug.dump.* php.ini settings. For the example below the settings in php.ini are:

Example:

xdebug.dump.GET=*
xdebug.dump.SERVER=REMOTE_ADDR

Query string:
?var=fourty%20two&array[a]=a&array[9]=b

Returns:

 
        
Dump $_SERVER
$_SERVER['REMOTE_ADDR'] =
 '127.0.0.1'
 (length=9)

Dump $_GET
$_GET['var'] =
 'fourty two'
 (length=10)

$_GET['array'] =
array

  'a' =>
 
 'a'
 (length=1)

  9 =>
 
 'b'
 (length=1)



void xdebug_var_dump( [mixed var [, ...]] )
Displays detailed information about a variable

This function displays structured information about one or more expressions that includes its type and value. Arrays are explored recursively with values. See the introduction of Variable Display Features on which php.ini settings affect this function.

Example:

<?php
ini_set
( 'xdebug.var_display_max_children' );
$c  = new  stdClass ;
$c -> foo  'bar' ;
$c -> file  fopen '/etc/passwd' 'r'  );
var_dump (
    array(
        array(
TRUE 2 3.14 'foo' ),
        
'object'  =>  $c
    
)
);
?>   

Returns:

 
        
array

  0 =>
 
    array

      0 =>
 
 true

      1 =>
 
 2

      2 =>
 
 3.14

      more elements...

  'object' =>
 
    object
(stdClass
)[1
]
      public
 'foo' =>
 
 'bar'
 (length=3)

      public
 'file' =>
 resource
(3
,
 stream
)




hen Xdebug is activated it will show a stack trace whenever PHP decides to show a notice, warning, error etc. The information that stack traces display, and the way how they are presented, can be configured to suit your needs.


The stack traces that Xdebug shows on error situations (if display_errors is set to On in php.ini) are quite conservative in the amount of information that they show. This is because large amounts of information can slow down both the execution of the scripts and the rendering of the stack traces themselves in the browser. However, it is possible to make the stack traces show more detailed information with different settings.

Variables in Stack Traces

By default Xdebug will now show variable information in the stack traces that it produces. Variable information can take quite a bit of resources, both while collecting or displaying. However, in many cases it is useful that variable information is displayed, and that is why Xdebug has the setting xdebug.collect_params . The script below, in combination with what the output will look like with different values of this setting is shown in the example below.

The script

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

set_time_limit ( 1 );
$c  = new  stdClass ;
$c -> bar  100 ;
$a  = array(
    
42  =>  false 'foo'  =>  912124 ,
    
$c , new  stdClass fopen '/etc/passwd' 'r'  )
);
foo $a  );
?>

The results

Different values for the xdebug.collect_params setting give different output, which you can see below:


( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 34
Call Stack
#TimeMemoryFunctionLocation
10.000158564{main}( )../stack.php: 0
20.000462764foo( )../stack.php: 47
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
#TimeMemoryFunctionLocation
10.000158132{main}( )../stack.php: 0
20.000462380foo( array(5) )../stack.php: 47
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
#TimeMemoryFunctionLocation
10.000158564{main}( )../stack.php: 0
20.000462812foo( array(5) )../stack.php: 47
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
#TimeMemoryFunctionLocation
10.000158564{main}( )../stack.php: 0
20.000462812foo( array (42 => FALSE, 'foo' => 912124, 43 => class stdClass { public $bar = 100 }, 44 => class stdClass { }, 45 => resource(2) of type (stream)) )../stack.php: 47
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
#TimeMemoryFunctionLocation
10.000158132{main}( )../stack.php: 0
20.000462380foo( $a = array (42 => FALSE, 'foo' => 912124, 43 => class stdClass { public $bar = 100 }, 44 => class stdClass { }, 45 => resource(2) of type (stream)) )../stack.php: 47

Additional Information

On top of showing the values of variables that were passed to each function Xdebug can also optionally show information about selected superglobals by using the xdebug.dump_globals and xdebug.dump.* settings. The settings xdebug.dump_once and xdebug.dump_undefined slightly modify when and which information is shown from the available superglobals. With the xdebug.show_local_vars setting you can instruct Xdebug to show all variables available in the top-most stack level for a user defined function as well. The examples below show this (the script is used from the example above).


( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 34
Call Stack
#TimeMemoryFunctionLocation
10.000158564{main}( )../stack.php: 0
20.000462764foo( )../stack.php: 47
ini_set('xdebug.collect_vars', 'on');
ini_set('xdebug.collect_params', '4');
ini_set('xdebug.dump_globals', 'on');
ini_set('xdebug.dump.SERVER', 'REQUEST_URI');

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 33
Call Stack
#TimeMemoryFunctionLocation
10.000158132{main}( )../stack.php: 0
20.000462436foo( )../stack.php: 47
Dump $_SERVER
$_SERVER['REQUEST_URI'] =
 '/test/xdebug/docs/stack.php?level=5'
 (length=35)

ini_set('xdebug.collect_vars', 'on');
ini_set('xdebug.collect_params', '4');
ini_set('xdebug.dump_globals', 'on');
ini_set('xdebug.dump.SERVER', 'REQUEST_URI');
ini_set('xdebug.show_local_vars', 'on');

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31
Call Stack
#TimeMemoryFunctionLocation
10.000158132{main}( )../stack.php: 0
20.000562588foo( )../stack.php: 47
Dump $_SERVER
$_SERVER['REQUEST_URI'] =
 '/test/xdebug/docs/stack.php?level=6'
 (length=35)


Variables in local scope (#2)
$a =
array

  42 =>
 
 false

  'foo' =>
 
 912124

  43 =>
 
    object
(stdClass
)[1
]
      public
 'bar' =>
 
 100

  44 =>
 
    object
(stdClass
)[2
]
  45 =>
 resource
(2
,
 stream
)
$i =
 275447


Related Settings

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值