关闭功能前的 PHP 分析延迟 [英] PHP profiling delay before shutdown function

查看:52
本文介绍了关闭功能前的 PHP 分析延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// VERY BEGIN OF SCRIPT
$_SERVER['HX_startTime'] = microtime(true);

...

// MY SHUTDOWN FUNCTION
register_shutdown_function('HX_shutdownFn');
function HX_shutdownFn()
{
    // formatTimeSpan is simple time to string conversion function
    var_dump(formatTimeSpan(microtime(true) - $_SERVER['HX_startTime']));
}


...

// VERY END OF SCRIPT
var_dump(formatTimeSpan(microtime(true) - $_SERVER['HX_startTime']));

我有0.0005s.在脚本和 1.1s 的末尾.在关机功能.正常吗?1秒在哪里丢失?

I've got 0.0005s. at end of script and 1.1s. at shutdown function. Is it normal? Where 1 second is lost?

脚本是纯php,不使用db连接等.在WAMP服务器上测试(php v 5.3.9,apache 2.2.21)

Script is pure php, does not use db connection, etc. Testing on WAMP server (php v 5.3.9, apache 2.2.21)

推荐答案

正如其他人提到的,可能还有其他关闭功能.此外,当对象超出范围(如果在全局范围内)时,会调用对象的析构函数.

As others have mentioned, there may be other shutdown functions. Additionally, there are the destructors of objects that are called when they go out of scope (if in the global scope).

您可以使用 XDebug 模块 (http://xdebug.org/) 详细了解所有这些,尤其是在使用跟踪文件时.一旦您安装并配置了 XDebug,您可以将 ?XDEBUG_TRACE=1 附加到您的 url 并查看整个页面执行的完整调用堆栈,包括每行的计时信息.

You can see all of this in glorious detail with the XDebug module (http://xdebug.org/), particularly when using the trace files. Once you have XDebug installed and configured, you can append ?XDEBUG_TRACE=1 to your url and see a full call stack for the entire execution of your page, including timing information for each line.

通过适当的选项,您还可以查看参数的分配、名称和值、返回值和赋值.这是一个非常强大和有用的工具.

With appropriate options, you can also see allocations, names and values of parameters, returned values, and assignments. It's a very powerful and useful tool.

这些是我用于 XDebug 的设置:

These are the settings I use for XDebug:

xdebug.default_enable=1
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
xdebug.profiler_append=On
xdebug.auto_trace=Off
xdebug.show_mem_delta=On
xdebug.collect_return=On
xdebug.collect_params=4
xdebug.profiler_output_dir = /tmp
xdebug.profiler_output_name = profile.%H.%t.%p
xdebug.var_display_max_children = 999
xdebug.var_display_max_data = 99999
xdebug.var_display_max_depth = 100
xdebug.remote_enable=1
xdebug.cli_color=1
xdebug.show_local_vars=1    
xdebug.show_mem_delta=1
xdebug.collect_return=1
xdebug.collect_assignments=1
xdebug.collect_params=4
xdebug.collect_includes=1
xdebug.trace_enable_trigger=1
xdebug.trace_output_dir=/tmp
xdebug.trace_output_name=trace.%t.%R.%p

这篇关于关闭功能前的 PHP 分析延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆