Articles: 843 | Categories: 148   
   
   
Home Articles Contact Us
 
 
 
 
Page Loading Time (0 Comments)
Admin: Posted Date: April 4, 2010

This tutorial will show you how to 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 Round the microtime and return it to the browser.

Page Loading Time

Things to do:
Get the time in micro-seconds using the function: microtime().
Turn the micro-time into an array using the explode() function.
Add the two parts to the array together (the micro-seconds to the seconds).
Repeat steps 1,2 and 3 for the bottom of the page
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
Round the microtime and return it to the browser



Put at the top of your page:

CODE

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



Put at the bottom of your page.
CODE

<?
$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";
?>

 

 
 
Add a Comment:
 
(You must be signed in to comment on an article. Not a member? Click here to register)
   
Title:

Comments: