php代码运行时间查看类代码分享

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

//date:2011-08-05
class RunTime//页面执行时间类
{
private $starttime;//页面开始执行时间
private $stoptime;//页面结束执行时间
private $spendtime;//页面执行花费时间
function getmicrotime()//获取返回当前微秒数的浮点数
{
list($usec,$sec)=explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function start()//页面开始执行函数,返回开始页面执行的时间
{
$this->starttime=$this->getmicrotime();
}
function end()//显示页面执行的时间
{
$this->stoptime=$this->getmicrotime();
$this->spendtime=$this->stoptime-$this->starttime;
//return round($this->spendtime,10);
}
function display()
{
//$this->end();
echo "<p>运行时间:".round($this->spendtime,10)."秒</p>";
}
}
/*调用方法
$timer=new Runtime();
$timer->start();

相关文章

PHP多人模块开发原理解析

PHP多人模块开发原理解析

作为世界上最“好”的语言,在web里占据着大概80%的份额,中小公司基本都说 lnmp 架构。当一个仓库开发人员大于1,20人的时候,每个人可能开发不同的模块和功能,用代码版本控制工具比...

php 验证码制作(网树注释思想)

1,生成随机数 用for循环确定生成几个随机数。 用随机函数生成范围内随机数。例如rand(1,15),生成1到15之间的数字。 用16位进制函数把生成数字字母化。dechex(rand...

PHP中Session和Cookie是如何操作的

Session PHP的$_SESSION可以存储当前用户数据信息,用户访问WEB网站的时候,PHP会给每个访问的用户创建一个session ID,该ID是唯一ID,保存在客户机上,而用...

PHP自带函数给数字或字符串自动补齐位数

先来看个例子:需求为生成4位数,不足前面补0 <?php //生成4位数,不足前面补0 $var=sprintf("%04d", 2); echo $var;/...

PHP file_get_contents设置超时处理方法

file_get_contents的超时处理 话说,从PHP5开始,file_get_content已经支持context了(手册上写着:5.0.0 Added the context...