Location: PHPKode > scripts > TimeConsumer > timeconsumer/TimeConsumer.php
<?php
// +----------------------------------------------------------------------+
// | Neutrino PHP Web Development Framework                               |
// +----------------------------------------------------------------------+
// | Neutrino is licensed using LGPL.                                     |
// +----------------------------------------------------------------------+
// | Author  : Ben Bi (from GuangZhou of China)                           |
// | Email   : hide@address.com                                       |
// | Blog    : http://bennybi.mblogger.cn                                 |
// +----------------------------------------------------------------------+
/**
* 
* @usage This class can let u easily embed and get the script running time information
* 
* 
* @version 	TimeConsumer.php, v0.1,  2009-4-3 15:08:08
* @package	
*/
    
    class TimeConsumer
    {
        ////for record script run time
        public static $DEBUG_SCRIPT_RUNTIME_START = 0.0;
        public static $DEBUG_SCRIPT_RUNTIME_END   = 0.0;
        public static $DEBUG_SCRIPT_RUNTIME_TOTAL = 0.0;
        
        public static function getMicrotimeFloat()
        {
            list($usec, $sec) = explode(" ", microtime());
            return ((float)$usec + (float)$sec);
        }
        
        public static function microTimeStart()
        {
            self::$DEBUG_SCRIPT_RUNTIME_START = self::getMicrotimeFloat();
        }
        
        public static function getRunTime()
        {
            self::$DEBUG_SCRIPT_RUNTIME_END = self::getMicrotimeFloat();
            self::$DEBUG_SCRIPT_RUNTIME_TOTAL = self::$DEBUG_SCRIPT_RUNTIME_END - self::$DEBUG_SCRIPT_RUNTIME_START;
            
            return self::$DEBUG_SCRIPT_RUNTIME_TOTAL;
        }
        
        public static function printOut($isReturn=false)
        {
            $tmpStr = '<h3>Running Time Consume Info:</h3>'.str_repeat('=',100).'<br/>';
            $tmpStr .= "This script runned in <font color='red'>".self::getRunTime()."</font> seconds<br/>\n";
            if($isReturn)
            {
                return $tmpStr;
            }
            else
            {
                echo $tmpStr;
            }
        }

        public static function getCurrentTime()
        {
            return date("Y-m-d H:i:s");
        }

        public static function currentTimePrintOut($target='', $isReturn=false)
        {
            $tmpStr = str_repeat("==", 50)."<br/>\n";
            $tmpStr .= "{$target} start at:".self::getCurrentTime()."  [".self::getMicrotimeFloat()." secs]<br/>\n";
            $tmpStr .= str_repeat("==", 50)."<br/>\n";
            if($isReturn)
            {
                return $tmpStr;
            }
            else
            {
                echo $tmpStr;
            }
        }
        
        public static function startTimePrintOut($target='', $isReturn=false)
        {
            $tmpStr = str_repeat("==", 50)."<br/>\n";
            $tmpStr .= "{$target} start at:".date("Y-m-d H:i:s", self::$DEBUG_SCRIPT_RUNTIME_START)."  [".self::$DEBUG_SCRIPT_RUNTIME_START." secs]<br/>\n";
            $tmpStr .= str_repeat("==", 50)."<br/>\n";
            if($isReturn)
            {
                return $tmpStr;
            }
            else
            {
                echo $tmpStr;
            }
        }

        public static function endTimePrintOut($target='', $isReturn=false)
        {
        	  self::getRunTime();
            $tmpStr = str_repeat("==", 50)."<br/>\n";
            $tmpStr .= "{$target} end at:".self::getCurrentTime()."  [".self::$DEBUG_SCRIPT_RUNTIME_END." secs]<br/>\n";
            $tmpStr .= str_repeat("==", 50)."<br/>\n";
            if($isReturn)
            {
                return $tmpStr;
            }
            else
            {
                echo $tmpStr;
            }
        }

        public static function setTimeZone($name='GMT')
        {
            date_default_timezone_set($name);
        }
       
    }
?>
Return current item: TimeConsumer