Browse By

Track Page Load Time With This Free Script Execution Class

Performance is very important to webmasters and a lot of times it would be nice to know how long on average it took for our web pages to load. I created a simple class in order to track how fast a page executes. This is written in PHP because that is what I use to develop my sites. It currently just displays the output on the page; I haven’t turned this into a log or database table yet but I probably will. Once I convert it to save the output each time, I could use it to track the averages per page. This is just a basic timer at the moment though. I have included the class and an example within the same PHP file below. You are free to use and change the script as you wish. Feel free to link back if you would like, but it is not mandatory.

<?

class LoadTime {

var $PageLoadStart;
var
$PageLoadEnd;

function PageStart() {
$this->PageLoadStart = microtime();
}

function PageEnd() {
$this->PageLoadEnd = microtime();
}

function LoadTime() {
return
round($this->PageLoadEnd$this->PageLoadStart,4);
}

}

$timer = new LoadTime();
$timer->PageStart();

$i = 0;
while (
$i<100000) {
$i++;
}

$timer->PageEnd();

echo $timer->LoadTime().‘ seconds’;

?>



2 thoughts on “Track Page Load Time With This Free Script Execution Class”

  1. Pingback: Recent Links Tagged With "loadtime" - JabberTags
  2. Trackback: Recent Links Tagged With "loadtime" - JabberTags
  3. Mike says:

    A class like this… is so not logical!
    You made a class, just to make one

Comments are closed.

%d bloggers like this: