php 頁面執(zhí)行時間計算代碼
更新時間:2008年12月04日 13:26:59 作者:
我們在開發(fā)網(wǎng)頁的時候,往往會測試一下自己寫的網(wǎng)頁的執(zhí)行時間是多少,例如:有時網(wǎng)頁打開很慢,但是不知道是卡在哪了,這時我們就可以使用以下的方法來判斷頁面的執(zhí)行時間是多少,準確的找到問題所在點,精確到毫秒。
代碼如下:
<?
$pagestartime=microtime();
?>
<!--網(wǎng)頁內(nèi)容 start-->
網(wǎng)頁內(nèi)容
...
...
<!--網(wǎng)頁內(nèi)容 end-->
<?
$pageendtime = microtime();
$starttime = explode(" ",$pagestartime);
$endtime = explode(" ",$pageendtime);
$totaltime = $endtime[0]-$starttime[0]+$endtime[1]-$starttime[1];
$timecost = sprintf("%s",$totaltime);
echo "頁面運行時間: $timecost 秒";
?>
復制代碼 代碼如下:
<?
$pagestartime=microtime();
?>
<!--網(wǎng)頁內(nèi)容 start-->
網(wǎng)頁內(nèi)容
...
...
<!--網(wǎng)頁內(nèi)容 end-->
<?
$pageendtime = microtime();
$starttime = explode(" ",$pagestartime);
$endtime = explode(" ",$pageendtime);
$totaltime = $endtime[0]-$starttime[0]+$endtime[1]-$starttime[1];
$timecost = sprintf("%s",$totaltime);
echo "頁面運行時間: $timecost 秒";
?>
相關文章
win7+apache+php+mysql環(huán)境配置操作詳解
本篇文章是對win7+apache+php+mysql環(huán)境配置的操作進行了詳細的分析介紹,需要的朋友參考下2013-06-06
php通過array_merge()函數(shù)合并兩個數(shù)組的方法
這篇文章主要介紹了php通過array_merge()函數(shù)合并兩個數(shù)組的方法,實例分析了php中array_merge()函數(shù)合并數(shù)組的使用技巧,需要的朋友可以參考下2015-03-03
PHP CURL模擬登錄新浪微博抓取頁面內(nèi)容 基于EaglePHP框架開發(fā)
PHP CURL模擬登錄新浪微博抓取頁面內(nèi)容 基于EaglePHP框架開發(fā),需要的朋友可以參考下。2012-01-01
PHP Class self 與 static 異同與使用詳解
這篇文章主要介紹了PHP中 Class self 與 static 有什么區(qū)別,都怎么用,需要的朋友們下面隨著小編來一起學習學習吧2021-09-09

