//计算执行时间,返回结果为毫秒
$ct = new cost_time();
$ct->set_time('start');
usleep(270000);
$ct->set_time('end');
echo $ct->get_cost_time();
class cost_time
{
private $start_time = 0;
private $end_time = 0;
public function set_time( $type='start' ) // 1:开始时间,2:结束时间
{
$time = microtime();
$s = explode(' ',$time);
$s = $s[1]*1 + $s[0]*1;
if( $type == 'start')
{
$this->start_time = $s;
}
else
{
$this->end_time = $s;
}
}
public function get_cost_time()
{
$rs = $this->end_time - $this->start_time;
$rs = number_format($rs,3);
return $rs*1000;
}
}