防google搜索统计脚本执行时间。

原创
2016-06-21 09:12:37 1547浏览

google|脚本|统计|执行


// class PHP_timer开始
class PHP_timer {

// 用来收集脚本执行过程中的信息
var $points = array();

// 在脚本的开始处调用这个函数
function start() {
// 请看后面的addmarker函数
$this->addmarker("Start");
}
// end function start()

// 在脚本的结束处调用这个函数
function stop() {
// 请看后面的addmarker函数
$this->addmarker("Stop");
}
// end function stop()

// 这个函数用来在脚本执行时增加一个标记
// 需要一个用来描述的名字
function addmarker($name) {
// 调用 jointime() 函数并将microtime() 的返回值传递过去
$markertime = $this->jointime(microtime());
// $ae 得到当前数组的大小,也就是当前的插入位置
// currently in the $points array
$ae = count($this->points);
// 在数组中存储timestamp 和说明
$this->points[$ae][0] = $markertime;
$this->points[$ae][1] = $name;
}
// end function addmarker()

// 这个函数会处理从microtime() 返回的字串
function jointime($mtime) {
// 分解字串
$timeparts = explode(" ",$mtime);
// 连接两个字串,并去除小数部分的0
$finaltime = $timeparts[1].substr($timeparts[0],1);
// 返回连接后的字串
return $finaltime;
}
// end function jointime()

// 这个函数简单的显示从开始到结束所需要的时间
function showtime() {
echo bcsub($this->points[count($this->points)-1][0],$this->points[0][0],6);
}
// end function showtime()

// 这个函数显示所有的在脚本运行过程中收集到的信息
function debug() {
echo "Script execution debug information:";
echo "

\n";
// 这个表格有3列 Marker name, Timestamp, difference
echo "\n";
// 第一行是没有运行时间差的
echo "\n";
echo "";
echo "";
echo "\n";
echo "\n";
// 从数组的元素1开始循环显示,0已经在第一行显示过了
for ($i = 1; $i points);$i++) {
echo "\n";
echo "";
echo "";
echo "";
echo "\n";
}
echo "
MarkerTimeDiff
".$this->points[0][1]."".$this->points[0][0]."-
".$this->points[$i][1]."".$this->points[$i][0]."";
// 显示上下两行的时间差
echo bcsub($this->points[$i][0],$this->points[$i-1][0],6);
echo "
";
}
// end function debug()
}
// end class PHP_timer

?>



声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。