Powered by Typecho)))
Optimized by EAimTY
见到网上有人把统计页面执行时间和数据库查询次数写成庞大的类~无语了,这么简单的东西也写成类,未免有点儿“OOP泛滥”了。
在页面最开头的地方写上:
1. $mtime = explode(' ', microtime());
2. $starttime = $mtime[1] + $mtime[0];
再在页面结束的地方写上
1. $mtime = explode(' ', microtime());
2. $totaltime = number_format(($mtime[1] + $mtime[0] - $starttime), 6);//保存小数点后6位
3. echo '页面执行时间:'.$totaltime.' second(s)';
就这么简单,而且可以控制小数点后保留数字的位数。
统计数据库查询次数更是简单:
在你的DB类里先
1. var $querycount = 0;//初始化为0
再在DB类里的query函数里添加上
# $this->querycount++;//每执行一次query函数就加一
再在需要显示的地方(一般也是页尾)写上
echo $DB->querycount.' queries';//打印数据库查询次数
就这么简单.