php扩展xdebug基本使用
官網(wǎng):http://www.xdebug.org/?
使用:http://www.xdebug.org/docs/
?
安裝
http://blog.csdn.net/21aspnet/article/details/7036087
?
使用
?
1.獲取文件名,行號(hào),函數(shù)名
xdebug_call_class()
<?php
??? function fix_string($a)
??? {
??????? echo "Called @ ".
??????????? xdebug_call_file().
??????????? ":".
??????????? xdebug_call_line().
??????????? " from ".
??????????? xdebug_call_function();
??? }
??? $ret = fix_string(array('Derick'));
?>
輸出:
Called @ /var/www/xdebug_caller.php:12 from {main}
?
2.輸出head信息
xdebug_get_headers()
<?php
header( "X-Test", "Testing" );
setcookie( "TestCookie", "test-value" );
var_dump( xdebug_get_headers() );
?>
輸出:
array(2) {[0]=>string(6) "X-Test"[1]=>string(33) "Set-Cookie: TestCookie=test-value"
}
?
?
3.輸出執(zhí)行時(shí)間
xdebug_time_index()
<?php
echo xdebug_time_index(), "\n";
for ($i = 0; $i < 250000; $i++)
{// do nothing
}
echo xdebug_time_index(), "\n";
?>
4.代碼覆蓋
xdebug_start_code_coverage();
代碼
var_dump(xdebug_get_code_coverage());
看圖更明顯
?
5.代碼跟蹤
需要跟蹤的代碼:
class myClass{public function a($a) {echo $a * 2.5;}public function b($b) {$this->a($b + 2);}
}
xdebug_start_trace('trace');
$obj=new myClass();
$obj->b(6);
echo "</br>";
xdebug_stop_trace();
--------------------------------------------------------------------------
xdebug配置參考
xdebug.default_enable = On
xdebug.show_exception_trace = On
xdebug.show_local_vars = 1
xdebug.max_nesting_level = 50
xdebug.var_display_max_depth = 6xdebug.dump_once = On
xdebug.dump_globals = On
xdebug.dump_undefined = On
xdebug.dump.REQUEST = *
xdebug.dump.SERVER = REQUEST_METHOD,REQUEST_URI,HTTP_USER_AGENTxdebug.trace_format = 0
xdebug.auto_trace = On
xdebug.trace_output_dir = E:\xampp\tmp\traces
xdebug.trace_output_name = trace.%c.%pxdebug.collect_params = 4
xdebug.collect_includes = On
xdebug.collect_return = On
xdebug.show_mem_delta = On
設(shè)置xdebug.auto_trace = Off可在代碼中添加xdebug_start_trace();xdebug_stop_trace();語句生成追蹤文件。
使用xdebug_start_trace跟蹤代碼執(zhí)行
xdebug_start_trace('trace');$a->myCaller($b);xdebug_stop_trace();TRACE START [16:53:57]0.0010 57964 -> MyClass->myCaller() /code/xdebug.php:210.0011 58104 -> MyOther->myCallee() /code/xdebug.php:40.0011 58104 -> xdebug_call_class() /code/xdebug.php:100.0011 58128 -> printf() /code/xdebug.php:100.0014 58196 -> xdebug_call_function() /code/xdebug.php:110.0015 58196 -> printf() /code/xdebug.php:110.0016 58196 -> xdebug_call_file() /code/xdebug.php:120.0016 58244 -> printf() /code/xdebug.php:120.0017 58244 -> xdebug_call_line() /code/xdebug.php:130.0017 58244 -> printf() /code/xdebug.php:130.0018 58244 -> xdebug_stop_trace() /code/xdebug.php:220.0019 58244TRACE END [16:53:57]
?
總結(jié)
以上是生活随笔為你收集整理的php扩展xdebug基本使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 糖心一套换雨露一套亏吗
- 下一篇: 为 PHP 应用提速、提速、再提速