php計算頁面執(zhí)行時間
在PHP網(wǎng)頁的開頭加入以下
<?
$time_start = getmicrotime();
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
?>
然后到最后加入以下代碼
<?
$time_end = getmicrotime();
printf ("[頁面執(zhí)行時間: %.2f毫秒]\n\n",($time_end - $time_start)*1000);
?>
************** Other code *************
<?php
$stime=microtime(true); //獲取程序開始執(zhí)行的時間
echo "hello world"; //你執(zhí)行的代碼
$etime=microtime(true);//獲取程序執(zhí)行結(jié)束的時間
$total=$etime-$stime; //計算差值
echo "<br />{$total} times";
?>
信息科技 2006-09-12 09:23:49 通過 網(wǎng)頁 瀏覽(3517) 打印