mctom987
mctom987

Reputation: 892

Best practice method to find execution time in Zend Framework

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.

Upvotes: 4

Views: 3166

Answers (3)

Marcin
Marcin

Reputation: 238497

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.

Upvotes: 3

Steve
Steve

Reputation: 3649

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

Upvotes: 3

Bill Karwin
Bill Karwin

Reputation: 562631

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

Upvotes: 1

Related Questions