PHP Classes

File: core/Timer.php

Recommend this page to a friend!
  Classes of Jonathan Alexey   JFWork   core/Timer.php   Download  
File: core/Timer.php
Role: Class source
Content type: text/plain
Description: Class source
Class: JFWork
Tiny framework based on the MVC design pattern
Author: By
Last change: Update of core/Timer.php
Date: 2 years ago
Size: 1,110 bytes
 

Contents

Class file image Download
<?php

class Timer {

    var
$_marker = array();

    function
__construct () {
       
// Init class Timer
   
}

    function
Timer (){
       
// Init class Timer
   
}

   
// Maker timer, and if stop = true get time and stop!
   
public function Marker ( $name , $stop = false){
        if(
$stop){
            if(!isset(
$this->_marker[$name])){
                return
false;
            }
           
$this->_marker[$name][1] = microtime();
            return
$this->getTime($name);
        }
       
$this->_marker[$name] = array(microtime());
        return
true;
    }

   
// get total time and stop timer
   
public function getTime( $name, $roundTo = 5 ) {

       
// If not exists maker return 0
        // It's a good one ?
       
if(!isset($this->_marker[$name])){
            return
"0";
        }
       
       
// Some fixed added
       
if(!isset($this->marker[$name][1])){
           
$this->_marker[$name][1] = microtime();
        }
       
       
// Mili + seconds
       
list($usec, $sec) = explode(" ", $this->_marker[$name][0]);
        list(
$usecF, $secF) = explode(" ", $this->_marker[$name][1]);
       
       
// plus
           
$be = ((float)$usec + (float)$sec);
           
$fi = ((float)$usecF + (float)$secF);
       
           
// return total time
           
return round($fi-$be,$roundTo);

    }

}
?>