在 Zend Framework 中查找执行时间的最佳实践方法

发布于 2024-09-11 23:51:11 字数 200 浏览 2 评论 0原文

我对查找 Zend Framework 应用程序的执行时间的最佳/标准方法感兴趣。目前,我正在 public/index.php 上启动计时器,然后在 Zend_Registry 中注册它,以供稍后调用,然后布局使用它来计算总时间。

有更好的方法吗?我知道这甚至不完全准确,因为 postDispatch() 中仍然(或至少可以)执行一些执行,该执行将在视图渲染后运行。

I'm interested in the best/standard way to find the execution time of my Zend Framework app. Currently I'm starting the timer on the public/index.php then registering it in Zend_Registry, for a later call, which the layout then uses to calculate the total time.

Is there a better way to do this? I know this isn't even entirely accurate, as there is still (or at least, can be) some execution in the postDispatch() which will be ran after the view is rendered.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

叹倦 2024-09-18 23:51:11

我最终

$appStartTime = microtime();

在引导程序启动之前添加了内容,并将其放在

global $appStartTime;
@list( $startMilli, $startSeconds, $endMilli, $endSeconds) = explode(' ',$appStartTime . ' ' . microtime());
$generateTime = ($endSeconds+$endMilli)-($startSeconds+$startMilli);
printf( '. Generated in %.3fs', $generateTime);
if ($generateTime > 1) // one second
{
    Zend_Registry::get( 'logger' )->warn( 'Long page load time of ' . $generateTime . ' on ' . Zend_Controller_Front::getInstance()->getRequest()->getRequestUri() );
}

layout.phtml的末尾作为结束主体标记之前的最后一件事

I ended up adding

$appStartTime = microtime();

before the bootstrapper got intsantiated, and put

global $appStartTime;
@list( $startMilli, $startSeconds, $endMilli, $endSeconds) = explode(' ',$appStartTime . ' ' . microtime());
$generateTime = ($endSeconds+$endMilli)-($startSeconds+$startMilli);
printf( '. Generated in %.3fs', $generateTime);
if ($generateTime > 1) // one second
{
    Zend_Registry::get( 'logger' )->warn( 'Long page load time of ' . $generateTime . ' on ' . Zend_Controller_Front::getInstance()->getRequest()->getRequestUri() );
}

at the end of my layout.phtml as the last thing before the closing body tag

ゃ懵逼小萝莉 2024-09-18 23:51:11

我自己使用 webgrind 和 xdebug 分析。这不仅提供了有关总执行时间的信息,还提供了给定方法执行的次数、执行时间等信息。

I myself use webgrind and xdebug profiling. This gives info not only about total execution time, but also e.g. how many times a given method was executed, what was the time of this execution, etc.

思念绕指尖 2024-09-18 23:51:11

您可能想考虑启用真正的代码分析器,例如 XHProf

You might want to look into enabling a real code profiler like XHProf.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文