<?php class ClockUtil { var $_clocks = array(); function Start($handler, $reset = false) { if (!isset($this->_clocks[$handler]) || $reset) { $this->_clocks[$handler] = $this->_GetTime(); return true; } else { trigger_error('The clock named '.$handler.' was already started!', E_USER_WARNING); return false; } } function Stop($handler) { if (isset($this->_clocks[$handler])) { $elapsedTime = $this->_GetTime() - $this->_clocks[$handler]; unset($this->_clocks[$handler]); return $elapsedTime; } else { trigger_error('The clock named '.$handler.' was not started!', E_USER_WARNING); return false; } } function Read($handler) { if (isset($this->_clocks[$handler])) { return $this->_GetTime() - $this->_clocks[$handler]; } else { trigger_error('The clock named '.$handler.' was not started!', E_USER_WARNING); return false; } } function _GetTime() { list($usec, $sec) = explode(' ', microtime()); return (float)$usec + (float)$sec; } } ?>
Egy kicsit szebb megoldás