Zend - The PHP Company




Date & Time

Add Code


microtime timer class  

Type: class
Added by: charles_killian
Entered: 28/06/2000
Last modified: 08/12/1999
Rating: ***** (6 votes)
Views: 7576
Time your PHP scripts. I took the "dealing with microtime" function and created a class. Now it is easy to start, stop and print out the elapsed time. Great for timing PHP scripts.


<?
class BC_Timer{
 
//properties 
 
var $stime;
 var 
$etime;
 
 
//methods
 
 //get_microtime function taken from Everett Michaud on Zend.com
 
function get_microtime(){
  
$tmp=split(" ",microtime());
  
$rt=$tmp[0]+$tmp[1];
  return 
$rt;
 }
//end get_microtime()
 
 
function start_time(){
  
$this->stime $this->get_microtime();
 }
//end start_time
 
 
function end_time(){
  
$this->etime $this->get_microtime();
 }
//end start_time
 
 
function elapsed_time(){
  return (
$this->etime $this->stime);
 }
//end start_time
 
}//end BC_Timer class
?>


Usage Example


<?
include "bc_timer.php";
$timer = new BC_Timer;
$timer->start_time();

sleep(5);

$timer->end_time();
print 
"<br><br>seconds in script: ";
print (
$timer->elapsed_time());
?>


Rate This Script





Search



This Category All Categories