In the given example we will learn how to generate and display the amount of time taken to load and display a specific page, for debugging or display purposes.
To get the loading time of your page just put the following code at the top of your page (Before )and that's it... There is a lot of confusing code there that you don't really need to worry about, but all you need is to get the initial time and final time, and everything will be sorted.
$m_time = explode(" ",microtime()); $m_time = $m_time + $m_time; $starttime = $m_time; $m_time = explode(" ",microtime()); $m_time = $m_time + $m_time; $endtime = $m_time; $totaltime = ($endtime - $starttime); echo "<b>Page loading took:</b>". $totaltime." seconds<br/>"; echo "<b>You can round the time taken by using round() function</b><br/>"; echo "<b>Page loading took:</b>".round($totaltime)."seconds";
Page loading took:2.7894973754883E-5 seconds
You can round the time taken by using round() function
Page loading took:0seconds
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: November 12, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles