例1,
在head.htm中加入,即在默认模版中添加:“$stime=microtime(true); //获取程序开始执行的时间”。
代码如下所示:
复制代码代码示例:
//这里是网页
//再在foot.htm修改,如下所示:
网页内容
...
...
$pageendtime = microtime();
$starttime = explode()(" ",$pagestartime);
$endtime = explode(" ",$pageendtime);
$totaltime = $endtime[0]-$starttime[0]+$endtime[1]-$starttime[1];
$timecost = sprintf()("%s",$totaltime);
echo "页面运行时间: $timecost 秒";
//by www.jbxue.com
?>
例3,
计算页面执行时间
在php网页的开头加入:
复制代码代码示例:
//计算页面执行时间
$time_start = getmicrotime();
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
?>
然后,在页面结尾加入:
复制代码代码示例:
$time_end = getmicrotime();
printf ("[页面执行时间: %.2f毫秒]\n\n",($time_end - $time_start)*1000);
//统计出当前页的执行时间
?>