PHP Get Page Load Stats - How to measure php script execution / load time
Seeing how this is the first result in Google I thought I'd share my solution to this problem. Put this at the top of your page:
$startScriptTime=microtime(TRUE);
And then put this code at the bottom of your page:
$endScriptTime=microtime(TRUE);$totalScriptTime=$endScriptTime-$startScriptTime;echo "\n\r".'<!-- Load time: '.number_format($totalScriptTime, 4).' seconds -->';
When you view source of a page you can see the load time in a comment on the last line of your HTML.
You can use this simple function to avoid the variable scope issue:
<?phpfunction timer(){ static $start; if (is_null($start)) { $start = microtime(true); } else { $diff = round((microtime(true) - $start), 4); $start = null; return $diff; }}timer();echo 'Page generated in ' . timer() . ' seconds.';