PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Page Loading Time
Your Ad Here

Page Loading Time


Page Loading TimeLearn how to output the time a page takes to load.

Have you ever noticed that lots of websites feature a little "Page loading took x.xxx seconds to load" at the bottom of their pages? It's a pretty simple thing to make and gives your site something that we all love... Stats!

Here is what we have to do:

  1. Get the time in micro-seconds using the function: microtime().
  2. Turn the micro-time into an array using the explode() function.
  3. Add the two parts to the array together (the micro-seconds to the seconds).
  4. Repeat steps 1,2 and 3 for the bottom of the page
  5. Find the total loading time by taking the time taken at the end of the page from the time taken at the top of the page
  6. Round the microtime and return it to the browser

Here is the code:

Put at the top of your page:

<? $m_time = explode(" ",microtime());
$m_time = $m_time[0] + $m_time[1];
$starttime = $m_time;
?>

Put at the bottom of your page.

<?
$round = 3;// The number of decimal places to round the micro time to.
$m_time = explode(" ",microtime());
$m_time = $m_time[0] + $m_time[1];
$endtime = $m_time;
$totaltime = ($endtime - $starttime);
echo "Page loading took:". round($totaltime,$round) ." seconds";
?>

That's it. If you have any questions, feel free to post about it and we'll try to help out.



Author's URL: KieranHall
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Add comments to "Page Loading Time"

Only registered users can write comment

No comments yet...