Benchmarking and testing your PHP script with microtime
$timer = new Timer;
$timer->start();
// some code...
$timer->stop();
// some more code...
$timer->stop(true);
/**
* PHP script execution timer
* @author Bohdan Zhuravel
* @version .1
*/
class Timer {
private $time;
const format =
"<strong>Execution Time</strong>: %s seconds<br />";
public function start() {
$this->_set();
}
public function stop($die = false) {
$this->_get() or $this->_set();
$s = round($this->_time() - $this->_get(), 4);
$this->_set();
printf(self::format, $s);
$die and die;
}
private function _get() {
return $this->time;
}
private function _set() {
$this->time = $this->_time();
}
private function _time() {
$time = explode(' ', microtime());
$time = $time[1] + $time[0];
return $time;
}
}
#php
#microtime
December 25, 2011 at 10:30pm
<?php
$today = date( "Y-m-d" );
$christmas = date( "Y-m-d", strtotime( "december 25" ) );
echo ( $today == $christmas ) ? "Merry Christmas!" : "";
?>
#php