页面执行时间怎么计算?

czcom 2003-09-01 06:46:56
像这里http://www.discuz.net/ 页角的页面执行时间,和数据库查询次数怎么计算?
大家帮帮我,想不明白 @_@
...全文
111 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
czcom 2003-09-01
  • 打赏
  • 举报
回复
可以了,3Q~~!
feel8 2003-09-01
  • 打赏
  • 举报
回复
错误代码贴出来,
使用时也要加上$db->query("",$Qnumber);
在开头也要初使化$Qnumber=0;
……
czcom 2003-09-01
  • 打赏
  • 举报
回复
有错误~~!
feel8 2003-09-01
  • 打赏
  • 举报
回复
在程序开头初始化查询次数为0,修改mysql。php的96行如下,并加上$Qnumber++;


function query($Query_String, &$Qnumber) {
$Qnumber++;
/* No empty queries, please, since PHP4 chokes on them. */
if ($Query_String == "")
/* The empty query string is passed on from the constructor,
* when calling the class without a query, e.g. in situations
* like these: '$db = new DB_Sql_Subclass;'
*/
return 0;

if (!$this->connect()) {
return 0; /* we already complained in connect() about that. */
};
czcom 2003-09-01
  • 打赏
  • 举报
回复
谢谢兄弟,我的数据库是使用phplib中的db_mysql.php来操作的,怎么样可以得到数据库操作数次?
feel8 2003-09-01
  • 打赏
  • 举报
回复
页面执行时间是在页面的头和尾分别加上代码,二个代码取得的值相减即可,

<?php
//functions.php
class proTime{
function headTime(){
$nowtime = explode(" ", microtime());
$starttime = $nowtime[1] + $nowtime[0];
return $starttime;
}

function footTime(){
global $starttime;
$nowtime = explode(" ", microtime());
$endtime = $nowtime[1] + $nowtime[0];
$totaltime = ($endtime - $starttime);
return number_format($totaltime, 7);
}

}
?>

<?php
//test.php
include_once("./functions.php");
$time = new proTime;
$starttime = $time-> headTime();
// do something
for ($i=0; $i<99999; $i++){

}

echo $time-> footTime();
?>


数据库查询次数,每次查询时使一个变量自加一,最后即可得出页面的数据库查询数次。

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧