澳门新葡萄京app下载
复制代码 代码如下: class Timer { private
$StartTime = 0;//程序运维发轫时间 private $StopTime =
0;//程序运转结束时间 private $TimeSpent = 0;//程序运维费用时间 function
start(){//程序运维开始 $this->Start提姆e = microtime{//程序启动结束$this->StopTime = microtime{//程序运营开销的时辰 if { return
$this->TimeSpent; } else { list($StartMicro, $StartSecond) =
explode(” “, $this->StartTime); list($StopMicro, $StopSecond) =
explode; $start = doubleval + $StartSecond; $stop = doubleval +
$StopSecond; $this->TimeSpent = $stop – $start; return
substr.”秒”;//重临获取到的程序运转时间差 } } } $timer = new Timer;
//…程序运维的代码 $timer->stop(); echo
“程序运维时间为:”.$timer->spent();
<?php
class runtime
{
var $StartTime = 0;
var $StopTime = 0;
function get_microtime()
{
list($usec, $sec) = explode(‘ ‘, microtime());
return ((float)$usec (float)$sec);
}
function start()
{
$this->StartTime = $this->get_microtime();
}
function stop()
{
$this->StopTime = $this->get_microtime();
}
function spent()
{
return round(($this->StopTime – $this->StartTime)
* 1000, 1);
}
}
代码如下
?>
代码如下
代码如下
<?php
//实例:计算页面运营时加载时间
//深入分析:页面展开时收获一个光阴,加载成功时收获叁个岁月,运转时刻即双方之差
//5.格式化输出
echo ‘<br />’;
$t = $end_time-$start_time;
echo round($t,2);
//2.拿走领头时间
$start_time = fn();
//5.加载进程
for($i=0;$i<10000000;$i++){
// do nothing;
}
这几天写了一个程序运营的时间计算类,供大家仿照效法: