Timer: Time page load time php ::Class::

Information for PHP. Hypertext Preprocessor
Post Reply
dzcadii
Posts: 94
Joined: Sun Mar 01, 2015 4:36 am

Timer: Time page load time php ::Class::

Post by dzcadii » Sun Mar 01, 2015 6:35 pm

Things to do 1st:
  • Create a new file for the class

Code: Select all

<?
/*****************************
     timer.class.php
*****************************/

class timer{

function timer_start(){

//Start time
$time = microtime();
$time = explode(" ", $time);
$time = $time['1'] + $time['0'];
$this->start = $time;
}


//End Time. This should be the last thing called in your scripts
function timer_end(){

$time = microtime();
$time = explode(" ", $time);
$time = $time['1'] + $time['0'];
$finish = $time;
$totaltime = ($finish - $this->start);

printf("%f seconds to load", $totaltime);

}

}
?>
Call the timer like this

Code: Select all

<?

/*****************************
     index.php
*****************************/
require_once('timer.class.php');

//Instantiate the timer class
$timer = new timer();

//Call the timer_start function in the timer class
$timer->timer_start();

echo "I am the body of your file<br><br><br>";

//Call the timer_end function in the timer class
$timer->timer_end();

?>

Post Reply