像这里http://www.discuz.net/ 页角的页面执行时间,和数据库查询次数怎么计算?
大家帮帮我,想不明白 @_@
---------------------------------------------------------------
页面执行时间是在页面的头和尾分别加上代码,二个代码取得的值相减即可,
1
2//functions.php
3class proTime{
4function headTime(){
5$nowtime = explode(" ", microtime());
6$starttime = $nowtime[1] + $nowtime[0];
7return $starttime;
8}
9
10function footTime(){
11global $starttime;
12$nowtime = explode(" ", microtime());
13$endtime = $nowtime[1] + $nowtime[0];
14$totaltime = ($endtime - $starttime);
15return number_format($totaltime, 7);
16}
17
18}
1
2//test.php
3include_once("./functions.php");
4$time = new proTime;
5$starttime = $time-> headTime();
6// do something
7for ($i=0; $i<99999; $i++){
8
9}
10
11echo $time-> footTime();
// ----------------------------------------------------------------------
数据库查询次数,每次查询时使一个变量自加一,最后即可得出页面的数据库查询数次。
使用phplib中db_mysql.php操作数据库计算数据库查询次数
修改db_mysql.php的96行如下,并加上$Qnumber++;
使用时也要加上$db->query("",$Qnumber);
在程序开头也要初使化$Qnumber=0;
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. */
};