xdebug所有相关方法函数详解(中文翻译版)

此次翻译部分借助google翻译,如有错误留言反馈 翻译时间:2016年4月18日09:41:34

xdebug.remote_enable = on
xdebug.profiler_enable = on
xdebug.profiler_enable_trigger = on
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "c:/wamp/tmp"

开启xdebug的相关的参数,安装编译这个不在这里介绍

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

这个方法被xdebug重载了,详细可以查看 xdebug_var_dump函数

打印出来的东西会和var_debug有些不同,会更详细


bool xdebug_break()
Emits a breakpoint to the debug client.
发送给客户端一个断点调试

This function makes the debugger break on the specific line as if a normal file/line breakpoint was set on this line.

此方法可以像在普通文件设置断点一样,在指定行设置一个断点


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


boolean xdebug_code_coverage_started()
Returns whether code coverage is active.

Returns whether code coverage has been started.

返回代码覆盖是不是开始

Example:

<?php
    var_dump(xdebug_code_coverage_started());

xdebug_start_code_coverage();

var_dump(xdebug_code_coverage_started());
?>

Returns:
bool(false)
bool(true)

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.

此方法显示一个,或者多个变量的包括类型,值,引用计数的相关信息,数组递归打印(探索,没找到对应的中文词,语境翻译)的值,这个方法实现方式和debug_zval_dump()不同,是为了解决变量变本身传递给函数的显示变量改变信息, Xdebug的版本是更好,因为它使用的变量名称查找变量在内部符号表并访问直接所有属性,而不必处理与实际传递变量的函数。其结果是,这个函数返回的信息比PHP自己的函数来显示zval的信息更加准确。

Support for anything but simple variable names (such as "a[2]" below) is supported since Xdebug 2.3.

Example:

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

xdebug_debug_zval('a');
    xdebug_debug_zval("a[2]");
?>

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)
a[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).

此功能显示关于一个或多个变量的结构化信息包括其类型,值和ref计数的信息的。数组与递归值探讨。与Xdebug的调试的zval的差异()是该信息不通过Web服务器API层显示,但在标准输出直接显示(所以,当你在单进程模式与Apache运行在控制台上结束了)

这个方法

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_disable()
Disables stack traces

Disable showing stack traces on error conditions.

禁用显示错误条件下的堆栈跟踪。


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:

此方法作为与指定此功能转储超级全局的元素的值。xdebug.dump的php.ini设置。对于低于在php.ini设置的例子是:

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'] =
string
 '127.0.0.1' (length=9)
Dump $_GET
$_GET['var'] =
string
 'fourty two' (length=10)
$_GET['array'] =
array
'a' =>

string

 'a' (length=1)
9 =>

string

 'b' (length=1)

void xdebug_enable()
Enables stack traces

Enable showing stack traces on error conditions.

开启显示错误条件下的堆栈跟踪


array xdebug_get_code_coverage()
Returns code coverage information

Returns a structure which contains information about which lines were executed in your script (including include files). The following example shows code coverage for one specific file:

返回一个结构包含哪行代码被执行到在你的脚本包括引入文件,下面的例子显示一个特定文件的代码覆盖:

Example:

<?php
    xdebug_start_code_coverage();

function a($a) {
        echo $a * 2.5;
    }

function b($count) {
        for ($i = 0; $i < $count; $i++) {
            a($i + 0.17);
        }
    }

b(6);
    b(10);

var_dump(xdebug_get_code_coverage());
?>

Returns:
array
'/home/httpd/html/test/xdebug/docs/xdebug_get_code_coverage.php' =>
array
5 =>

int

      6 => 

int

      7 => 

int

      9 => 

int

      10 => 

int

      11 => 

int

      12 => 

int

      13 => 

int

      15 => 

int

      16 => 

int

      18 => 

int



void xdebug_get_collected_errors( [int clean] )
Returns all collected error messages
Introduced in version 2.1

This function returns all errors from the collection buffer that contains all errors that were stored there when error collection was started withxdebug_start_error_collection().

当开启xdebug_start_error_collection()的时候此方法会返回所有错误信息,从返回缓冲区的所有错误

By default this function will not clear the error collection buffer. If you pass true as argument to this function then the buffer will be cleared as well.

默认情况下此功能将不能清除错误收集缓冲区。如果作为参数传递true给这个函数则缓冲区也将被清除

This function returns a string containing all collected errors formatted as an "Xdebug table".

该函数返回一个包含格式化为“的Xdebug表”收集的所有错误的字符串。


array xdebug_get_declared_vars()
Returns declared variables

Returns an array where each element is a variable name which is defined in the current scope. The setting xdebug.collect_vars needs to be enabled.

Example:

<?php
    class strings {
        static function fix_strings($a, $b) {
            foreach ($b as $item) {
            }
            var_dump(xdebug_get_declared_vars());
        }
    }
    strings::fix_strings(array(1,2,3), array(4,5,6));
?>

Returns:
array
0 =>

string

 'a' (length=1)
1 =>

string

 'b' (length=1)
2 =>

string

 'item' (length=4)

In PHP versions before 5.1, the variable name "a" is not in the returned array, as it is not used in the scope where the function xdebug_get_declared_vars() is called in.


array xdebug_get_function_stack()
Returns information about the stack

Returns an array which resembles the stack trace up to this point. The example script:

返回它类似于堆栈跟踪到这一点

Example:

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

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

$s = new strings();
    $ret = $s->fix_strings(array('Derick'));
?>

Returns:
array
0 =>
array
'function' =>

string

 '{main}' (length=6)
'file' =>

string

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

int

      '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

      '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

      'params' =>
array
'a' =>

string

 ''Derick'' (length=8)

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

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.

返回所有已设置使用PHP header()函数,或任何其他头在PHP内部设置(如通过setcookie()函数)的标题,作为一个数组

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"
}

array xdebug_get_monitored_functions()
Returns information about monitored functions
Introduced in version 2.4

Returns a structure which contains information about where the monitored functions were executed in your script. The following example shows how to use this, and the returned information:

返回一个包含关于那里的监控功能在你的方法被执行信息的结构。下面的示例演示如何使用此,返回的信息

Example:

<?php
/* Start the function monitor for strrev and array_push: */
xdebug_start_function_monitor( [ 'strrev', 'array_push' ] );

/* Run some code: */
echo strrev("yes!"), "\n";

echo strrev("yes!"), "\n";

var_dump(xdebug_get_monitored_functions());
xdebug_stop_function_monitor();
?>

Returns:
/tmp/monitor-example.php:10:
array(2) {
[0] =>
array(3) {
'function' =>
string(6) "strrev"
'filename' =>
string(24) "/tmp/monitor-example.php"
'lineno' =>
int(6)
}
[1] =>
array(3) {
'function' =>
string(6) "strrev"
'filename' =>
string(24) "/tmp/monitor-example.php"
'lineno' =>
int(8)
}
}

string xdebug_get_profiler_filename()
Returns the profile information filename

Returns the name of the file which is used to save profile information to.

返回其用于保存分析信息的文件的名称。


integer xdebug_get_stack_depth()
Returns the current stack depth level

Returns the stack depth level. The main body of a script is level 0 and each include and/or function call adds one to the stack depth level.

返回堆栈深度级别。一个脚本的主体是级别为0并且每个包括和/或功能调用添加一个到堆栈深度级别


string xdebug_get_tracefile_name()
Returns the name of the function trace file

Returns the name of the file which is used to trace the output of this script too. This is useful when xdebug.auto_trace is enabled.

返回一个也是用于跟踪该脚本的输出的文件名称。当启用xdebug.auto_trace时,这是非常有用的


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.

返回脚本使用的当前内存容量。 PHP5.2.1之前,如果PHP使用--enable-memory限制编译这仅适用。从PHP5.2.1和此功能后始终可用。


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.

返回的最大内存使用量直到现在脚本。 PHP5.2.1之前,如果PHP使用--enable-memory限制编译这仅适用。从PHP5.2.1和此功能后始终可用。


none xdebug_print_function_stack( [ string message [, int options ] ] )
Displays the current function stack.

Displays the current function stack, in a similar way as what Xdebug would display in an error situation.

显示当前的函数的堆栈,与Xdebug显示一个错误的情况类似。

The "message" argument allows you to replace the message in the header with your own. (Introduced in Xdebug 2.1).

消息”的说法可以让你用自己的头更换信息。 (在2.1 Xdebug的引入)。

Example:

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

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

The bitmask "options" allows you to configure a few extra options. The following options are currently supported:

该位掩码“选项”,可以配置一些额外的选项。下列选项目前支持

XDEBUG_STACK_NO_DESC
If this option is set, then the printed stack trace will not have a header. This is useful if you want to print a stack trace from your own error handler, as otherwise the printed location is where xdebug_print_function_stack() was called from. (Introduced in Xdebug 2.3).

如果这个选项被设置,那么打印的堆栈跟踪不会有一个标题。如果您想从自己的错误处理打印堆栈跟踪,否则打印的位置是Xdebug的print_function栈()从所谓的,这非常有用。 (在Xdebug的2.3引入)。


void xdebug_start_code_coverage( [int options] )
Starts code coverage

This function starts gathering the information for code coverage. The information that is collected consists of an two dimensional array with as primary index the executed filename and as secondary key the line number. The value in the elements represents whether the line has been executed or whether it has unreachable lines.

此方法开始收集代码覆盖的信息。所收集的信息包括与作为主索引的执行文件名和作为第二密钥的行号的二维阵列中的元素的值表示该行是否已被执行或是否具有不可到达行数

The returned values for each line are:

  • 1: this line was executed
  • -1: this line was not executed
  • -2: this line did not have executable code on it

Value -1 is only returned when the XDEBUG_CC_UNUSED is enabled and value -2 is only returned when both XDEBUG_CC_UNUSED and XDEBUG_CC_DEAD_CODE are enabled.

This function has two options, which act as a bitfield:

XDEBUG_CC_UNUSED
Enables scanning of code to figure out which line has executable code. Without this option you the returned array will only have lines in them that were actually executed.
XDEBUG_CC_DEAD_CODE
Enables branch analyzes to figure out whether code can be executed.

Enabling those options make code coverage drastically slower.

You can use the options as shown in the following example.

Example:

<?php
xdebug_start_code_coverage( XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );
?>


void xdebug_start_error_collection()
Starts recording all notices, warnings and errors and prevents their display
Introduced in version 2.1

When this function is executed, Xdebug will cause PHP not to display any notices, warnings or errors. Instead, they are formatted according to Xdebug's normal error formatting rules (ie, the error table with the red exclamation mark) and then stored in a buffer. This will continue until you callxdebug_stop_error_collection().

当执行此功能时,Xdebug的将导致PHP不显示任何通知,警告或错误。相反,它们根据Xdebug的正常错误格式规则(即,用红色惊叹号误差表),然后存储在缓冲器格式化。这将继续下去,直到你调用debug_stop_error_collection()

This buffer's contents can be retrieved by calling xdebug_get_collected_errors() and then subsequently displayed. This is really useful if you want to prevent Xdebug's powerful error reporting features from destroying your layout.

该缓冲区的内容可以通过调用的XDebug get_collected_errors(检索),随后显示。如果你想阻止破坏你的布局的Xdebug强大的错误报告功能,这是非常有用的。


void xdebug_start_function_monitor( array $list_of_functions_to_monitor )
Starts function monitoring
Introduced in version 2.4

This function starts the monitoring of functions that were given in a list as argument to this function. Function monitoring allows you to find out where in your code the functions that you provided as argument are called from. This can be used to track where old, or, discouraged functions are used.

此功能的启动列表中被赋予作为参数给这个函数的功能进行监测。功能监测可以让你找出你的代码,您作为参数提供的功能从调用。这可以用于跟踪旧或者不被建议使用功能

Example:

<?php
xdebug_start_function_monitor( [ 'strrev', 'array_push' ] );
?>

You can also add class methods and static methods to the array that defines which functions to monitor. For example, to catch static calls to DramModel::canSee and dynamic calls to Whisky->drink, you would start the monitor with:

您还可以添加类方法和静态方法来定义要监视的函数的数组。例如,为了赶上静态调用DramModel::可以看到,动态调用Whisky->酒后,你会开始监控,包括:

Example:

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

The defined functions are case sensitive, and a dynamic call to a static method will not be caught.

所定义的功能是区分大小写的,并且静态方法动态调用时才会被发现。


void xdebug_start_trace( string trace_file [, integer options] )
Starts a new function trace
开始一个新方法的追踪

Start tracing function calls from this point to the file in the trace_file parameter. If no filename is given, then the trace file will be placed in the directory as configured by the xdebug.trace_output_dir setting. In case a file name is given as first parameter, the name is relative to the current working directory. This current working directory might be different than you expect it to be, so please use an absolute path in case you specify a file name. Use the PHP function getcwd() to figure out what the current working directory is.

开始从该点到跟踪文件中的参数的文件跟踪函数调用。如果没有文件名给出,然后跟踪文件将被放置在目录中配置由xdebug.trace OUTPUT_DIR设置。如果一个文件名作为第一个参数,该名称是相对于当前的工作目录。这个当前工作目录可能会有所不同和你希望的,所以请使用你指定一个文件名的绝对路径。使用PHP函数 getcwd()找出当前工作目录是什么

The name of the trace file is "{trace_file}.xt". If xdebug.auto_trace is enabled, then the format of the filename is "{filename}.xt" where the "{filename}" part depends on the xdebug.trace_output_name setting. The options parameter is a bitfield; currently there are three options:

跟踪文件的名称为“{跟踪文件}.xt”。如果xdebug.auto_trace被启用,那么文件名格式为“{文件名}.xt”,其中“{文件名}”部分取决于xdebug.trace output_name中设置。选项参数是一个位域;目前有三种选择:

XDEBUG_TRACE_APPEND (1)
makes the trace file open in append mode rather than overwrite mode
使得跟踪文件以追加方式打开,而不是覆盖模式
XDEBUG_TRACE_COMPUTERIZED (2)
creates a trace file with the format as described under 1 "xdebug.trace_format".
创建具有下1“xdebug.trace格式”中所述格式的跟踪文件。
XDEBUG_TRACE_HTML (4)
creates a trace file as an HTML table
创建一个追踪文件的html 表哥
XDEBUG_TRACE_NAKED_FILENAME (8)
Normally, Xdebug always adds ".xt" to the end of the filename that you pass in as first argument to this function. With theXDEBUG_TRACE_NAKED_FILENAME flag set, ".xt" is not added. (New in Xdebug 2.3).
通常情况下,Xdebug的总是添加“.Xt”您在传递的第一个参数此功能的文件名末尾。随着theXDEBUG_TRACE_NAKED_FILENAME标志设置,“.xt”不添加。 (新增Xdebug的2.3)。

Unlike Xdebug 1, Xdebug 2 will not store function calls in memory, but always only write to disk to relieve the pressure on used memory. The settingsxdebug.collect_includesxdebug.collect_params and xdebug.collect_return influence what information is logged to the trace file and the settingxdebug.trace_format influences the format of the trace file.


void xdebug_stop_code_coverage( [int cleanup=true] )
Stops code coverage

This function stops collecting information, the information in memory will be destroyed. If you pass "false" as argument, then the code coverage information will not be destroyed so that you can resume the gathering of information with the xdebug_start_code_coverage() function again.

该功能将停止收集的信息,在内存中的信息将被销毁。如果传递“假”的说法,那么代码覆盖率信息不会被破坏,这样就可以再次恢复与xdebug_start_code_coverage()函数的信息收集。


void xdebug_stop_error_collection()
Stops recording of all notices, warnings and errors as started by xdebug_start_error_collection()
Introduced in version 2.1

停止所有注意,警告和错误的记录作为发起者的XDebug start_error_collection()
推出2.1版本

When this function is executed, error collection as started by xdebug_start_error_collection() is aborted. The errors stored in the collection buffer are not deleted and still available to be fetched through xdebug_get_collected_errors().

当执行此功能,错误集合作为通过xdebug_start_error_collection()被中止。存储在采集缓冲器中的误差不会被删除,并仍可通过Xdebug的get_collected_errors可读取()。


void xdebug_stop_function_monitor()
Stops monitoring functions
Introduced in version 2.4

This function stops the function monitor. In order to get the list of monitored functions, you need to use the xdebug_get_monitored_functions()function.

此功能停止功能监测。为了得到的监测功能的列表中,您需要使用xdebug_get_monitored_functions()函数。


void xdebug_stop_trace()
Stops the current function trace

Stop tracing function calls and closes the trace file.

停止跟踪函数调用和关闭跟踪文件。


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

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.

此功能显示关于包括其类型和值的一个或多个表达式结构化信息。数组与递归值探讨。看到介绍上php.ini的影响这个功能可变显示功能的。

Example:

<?php
ini_set('xdebug.var_display_max_children', 3 );
$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 =>

boolean

 true
1 =>

int

      2 => 

float

 3.14
more elements...
'object' =>
object(stdClass)[1]
public 'foo' =>

string

 'bar' (length=3)
public 'file' => resource(3, stream)
上一篇:Linux瑞士军刀:密码管理Keeweb


下一篇:Java使用HTTPClient4.3开发的公众平台消息模板的推送功能