PHP5中才生效。这个函数是PHP开发团队在PHP5中新增的函数,然后又反向移植到PHP4.3中。
Xdebug使调试信息更加美观
Xdebug扩展加载后,Xdebug会对原有的某些PHP函数进行覆写,以便好更好地进行Debug。比如var_dump()函数,我们知道通常我们需要在函数前后加上”<pre>…</pre>”才能够让输出的变量信息比较美观、可读性好。但是加载了Xdebug后,我们不再需要这样做了,Xdebug不但自动给我们加上了<pre>标签,还给变量加上颜色。
例:
<?php
$arrTest=array(
"test"=>"abc",
"test2"=>"abc2"
);
var_dump($arrTest);
?>看到了吗? 数组元素的值自动显示颜色。
Xdebug测试脚本执行时间
测试某段脚本的执行时间,通常我们都需要用到microtime()函数来确定当前时间。例如PHP手册上的例子:
<?php
/**
* Simple function to replicate PHP 5 behaviour
*/
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
// Sleep for a while
usleep(100);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "Did nothing in $time seconds\n";
?>Xdebug自带了一个函数xdebug_time_index()来显示时间。
PHP脚本占用的内存
有时候我们想知道程序执行到某个特定阶段时到底占用了多大内存,为此PHP提供了函数memory_get_usage()。这个函数只有当PHP编译时使用了--enable-memory-limit参数时才有效。
Xdebug同样提供了一个函数xdebug_memory_usage()来实现这样的功能,另外xdebug还提供了一个xdebug_peak_memory_usage()函数来查看内存占用的峰值。
gmail.com