Track Page Load Time With This Free Script Execution Class

1

Posted by Scott Spear in PHP,Tutorial,Webmaster | Tags: , , , ,

Friday, August 1, 2008

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';

?>

About the author: Scott Spear

I have been designing and programming on the web for 10 years and still have so much more to learn. I hope to use what I have learned from my MBA to mix business with web technologies in future endeavors.

One comment

Post your own

[...] Landing Page Load Time Affecting PPC Quality Score Saved by SarahKate on Fri 26-12-2008 Track Page Load Time With This Free Script Execution Class Saved by ibanezc on Fri 26-12-2008 Test your website load time with one click Saved by [...]

Leave a Reply