最新消息:

PHP脚本/页面执行时间类

PHP admin 1浏览

计算脚本/页面执行时间的类,贴出来希望对有些朋友有用。

class processtime {
var $starttime, $endtime;
function start() {
$this->starttime = $this->nowtime();
}
function end() {
$this->endtime = $this->nowtime();
}
function elapsed() {
$processtime = $this->endtime – $this->starttime;
return number_format($processtime, 7);
}
function nowtime() {
$now = explode(” “, microtime());
return $now[1] + $now[0];
}
}

==== 使用方法 ====
在脚本/页面开始处创建一个实例:

$itime = new processtime;

在脚本/页面开始和结束处分别调用start()和end()方法:

$itime->start();
/
SOME CODE HERE
/
$itime->end();

在需要显示的位置调用elapsed()方法:

echo ‘Processed in ‘.$itime->elapsed().’ second(s).’;

相关日志PHP Warning: PHP Startup: pdo_mysql: Unable to initialize module
升级最新 Nginx Mysql Php
PHP关闭浏览器后仍然继续执行的函数
PHP 基于文件头的文件类型验证类
几个有用的php字符串过滤,转换函数

转载请注明:爱开源 » PHP脚本/页面执行时间类