2017-03-16 23 views
0

我正在處理一個長輪詢ajax腳本直到我意識到我的php腳本的執行時間永遠不會結束。 我做了以下內容:php最大執行時間永不結束

<?php 
set_time_limit(11); 
ini_set('max_execution_time',11); 
echo ini_get('max_execution_time'); 

$i=0; 
while (true) { 
    $i++; 
    echo "<br>".$i; 
    sleep(1); 
} 
echo "END"; 
?> 

我得到的第一行如我所料; 「11」。 但腳本仍在計數...我保持頁面呼應...我不知道什麼時候會完成 有沒有什麼建議?我沒有訪問服務器,它是在ehost.com

+0

首先是11,在那之後1 ......參照圖12,致命錯誤後:在c超過11秒最大執行時間:\ XAMPP \ htdocs中\ PHP7 \ timeneverstop第7行的.php你想要什麼? – b2ok

+0

該腳本不斷計數...正確知道回聲超過800 ...所以... –

+0

它看起來像是依賴於操作系統 - 即在Linux睡眠()時間被忽略,所以max_execution_time指的是實際運行時間,不包括睡覺時間。請參閱:http://stackoverflow.com/questions/740954/does-sleep-time-count-for-execution-time-limit – manassehkatz

回答

0

Check this docs

Warning
This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.

也許這是你的問題。無論如何也從safe mode's docs

Warning This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

+0

雖然這是我第一次,但在[PHP文檔](http://php.net/manual/en/features.safe-mode.php)中說:「此功能已從PHP 5.3.0和DEPRECATED從PHP 5.4.0刪除「和我的版本是5.6.29 –

+0

[This](http://stackoverflow.com/questions/12094839/php-set-time-limit-does-not-work-safemode-is-關閉)也可以幫助你。 – Condorcho

+0

另外[檢查此](http://stackoverflow.com/questions/7493023/why-doesnt-set-time-limit-work-as-expected),特別是[這個答案](http://stackoverflow.com/ a/7493056/7431119) – Condorcho