Add*_*ons 1 php performance hook
我基本上可以这样做:
register_function_hook('myFunctionHook');
Run Code Online (Sandbox Code Playgroud)
所以当运行任何函数时:
functionA(); //The hook runs myFunctionHook();
anoterFunction(); //The hook runs myFunctionHook();
Class::functionA(); //The hook runs myFunctionHook();
Run Code Online (Sandbox Code Playgroud)
这样的事情存在吗?
- 编辑 -
我想要做的是获得每个功能的持续时间细分.IE浏览器.性能调优.我想知道在我的Apache服务器上没有安装xDebug时会花费多少时间,但是我不知道是否可能.
这是可能的register_tick_function(),也请查看PHP手册上的这条评论:
$script_stats = array();
$time = microtime(true);
function track_stats(){
global $script_stats,$time;
$trace = debug_backtrace();
$exe_time = (microtime(true) - $time) * 1000;
$func_args = implode(", ",$trace[1]["args"]);
$script_stats[] = array(
"current_time" => microtime(true),
"memory" => memory_get_usage(true),
"file" => $trace[1]["file"].': '.$trace[1]["line"],
"function" => $trace[1]["function"].'('.$func_args.')',
"called_by" => $trace[2]["function"].' in '.$trace[2]["file"].': '.$trace[2]["line"],
"ns" => $exe_time
);
$time = microtime(true);
}
declare(ticks = 1);
register_tick_function("track_stats");
// the rest of your project code
// output $script_stats into a html table or something
Run Code Online (Sandbox Code Playgroud)
这"挂钩"到一切,不仅仅是功能,但我认为它符合你的目的.