当前位置:编程学习 > php >>

PHP 一个页面执行时间类代码

答案:
复制代码 代码如下:

<?php
class Timer//页面执行时间类
{
var starttime;//页面开始执行时间
var stoptime;//页面结束执行时间
var spendtime;//页面执行花费时间
function getmicrotime()//获取返回当前微秒数的浮点数
{
list(usec,sec)=explode(" ",microtime());
return ((float)usec + (float)sec);
}
function start()//页面开始执行函数,返回开始页面执行的时间
{
this->starttime=this->getmicrotime();
}
function display()//显示页面执行的时间
{
this->stoptime=this->getmicrotime();
this->spendtime=this->stoptime-this->starttime;
return round(this->spendtime,10);
}
}
/*调用方法
timer=new Timer();
timer->start();
/*在此处放入你要执行的脚本或代码
for(i=0;i<100000;i++)
{
echo i;
echo "<br>";
}
*/
//echo "<p>执行该代码花费时间".timer->display()."秒";
?>

上一个:php 修改zen-cart下单和付款流程以防止漏单
下一个:PHP开启gzip页面压缩实例代码

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,