Saturday, November 28, 2009

PHP: Page loading time


We sometimes see that page loading time is mentioned at the bottom. For example, "Page loaded in x.xx seconds." Below is the method for showing that in your php pages.

1. Add the following code at the top of the .php file:

function utime (){
$time = explode( " ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
return $sec + $usec;
}
$start = utime();
?>

2. Add the following code at the end of the .php file:

$end = utime(); $run = $end - $start; echo "Page loaded in " . substr($run, 0, 5) . " seconds.";
?>

After this code is installed you may see something like this:
Page loaded in 0.65 seconds.

0 comments:

Post a Comment

Random Posts

Visitors

free counters

Add Us in Your Circles

  © Ink of life 2017 | Privacy Policy

ProBlogger Template by Ourblogtemplates.com

Back to TOP