復制代碼 代碼如下:
 
<?php 
ignore_user_abort();//關掉瀏覽器,PHP腳本也可以繼續執行. 
set_time_limit(3000);// 通過set_time_limit(0)可以讓程序無限制的執行下去 
$interval=5;// 每隔5s運行 
//方法1--死循環 
do{ 
echo '測試'.time().'<br/>'; 
sleep($interval);// 等待5s 
}while(true); 
//方法2---sleep 定時執行 
require_once './curlClass.php';//引入文件 
$curl = new httpCurl();//實例化 
$stime = $curl->getmicrotime(); 
for($i=0;$i<=10;$i++){ 
echo '測試'.time().'<br/>'; 
sleep($interval);// 等待5s 
} 
ob_flush(); 
flush(); 
$etime = $curl->getmicrotime(); 
echo '<hr>'; 
echo round(($etime-stime),4);//程序執行時間 
測試的時候發現這個效率并不是很高,
新聞熱點
疑難解答