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
Ask Questions? Discuss: PHP Generate a pages loading time Tutorial
Post your Comment
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.