页面执行时间是在页面的头和尾分别加上代码,二个代码取得的值相减即可,<?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();
?>
数据库查询次数,每次查询时使一个变量自加一,最后即可得出页面的数据库查询数次。
//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();
?>
数据库查询次数,每次查询时使一个变量自加一,最后即可得出页面的数据库查询数次。
解决方案 »
- header("location".$url)不能用于if语句中?
- 怎样设定iis执行时间 我上传文件到网站,五分钟就断了
- 一个字符串不能存入数据库的问题
- 留言板上传到空间后显示错误怎么解决?
- PHP调用WebService,求大神帮忙看下~
- 关于php预处理查询问题
- 我想做这么件事,http://xxxxxx/save.php?1234556890abcm之后,把1234567890abcm这些save.php带的参数保存到服务器上当前目录下的save.tx
- 在FCKedeitor中加功能
- 很有难度的问题,看看那位大侠能帮帮手!
- 斑竹!我的专家分怎么减少了?
- 对于一个双精度数,如何取得小数点后两位?
- 一般网站上的相关链接是怎么做的?要用哪些技术?UP有分!
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. */
};
使用时也要加上$db->query("",$Qnumber);
在开头也要初使化$Qnumber=0;
……