开发者

Best practice method to find execution time in Zend Framework

开发者 https://www.devze.com 2023-01-08 22:45 出处:网络
I\'m interested in the best/standard way to find the execution time of 开发者_Python百科my Zend Framework app. Currently I\'m starting the timer on the public/index.php then registering it in Zend_Reg

I'm interested in the best/standard way to find the execution time of 开发者_Python百科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.


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消