页面执行时间是在页面的头和尾分别加上代码,二个代码取得的值相减即可,<?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();
?>
数据库查询次数,每次查询时使一个变量自加一,最后即可得出页面的数据库查询数次。

解决方案 »

  1.   

    谢谢兄弟,我的数据库是使用phplib中的db_mysql.php来操作的,怎么样可以得到数据库操作数次?
      

  2.   

    在程序开头初始化查询次数为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. */
        };
      

  3.   

    错误代码贴出来,
    使用时也要加上$db->query("",$Qnumber);
    在开头也要初使化$Qnumber=0;
    ……