页面执行时间是在页面的头和尾分别加上代码,二个代码取得的值相减即可,<?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();
?>
数据库查询次数,每次查询时使一个变量自加一,最后即可得出页面的数据库查询数次。
解决方案 »
- 请教:怎么让windows每隔一段时间执行一个php 程式?
- 100分求解,请详细解释
- PHP中的编辑器如何在后天添加格式后前台现实输出格式
- Your browser (or proxy) sent a request that this server could not understand在线等急
- 请问如果一个标中有5个字段都在 where子句中出现,那么是要建立5个索引吗
- 「求助」关于PHP回调函数的疑问
- 请问:用 global 定义变量会不会影响运行速度呢?
- 用哪位兄弟在LINUX下使用PHP吗?帮帮我!
- 新手问题!
- 数组更换赋值形式后,图像出现一堆乱码,紧急求援,在线等待中.......
- 对于一个双精度数,如何取得小数点后两位?
- 一般网站上的相关链接是怎么做的?要用哪些技术?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;
……