2013-04-11 66 views
0

我想有一個推連接到我的客戶。如果文件包含單詞true,則應該通知它。這適用於以下腳本,但在50秒後我總是得到一個錯誤。你在下面看到這個錯誤。死循環返回錯誤

我怎樣才能解決這個問題?

<?php 
    set_time_limit(3600); 
    $content =""; 
    while($content!="true"){ 
     sleep(1); 
     $content = file_get_contents("test.txt"); 
    } 
    echo "now"; 

?> 

'這裏是瀏覽器在50秒後的結果。

Internal Server Error 

The server encountered an internal error or misconfiguration and was unable to complete your request. 

Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error. 

More information about this error may be available in the server error log. 

我的Apache配置:

# 
# Timeout: The number of seconds before receives and sends time out. 
# 
Timeout 3600 

# 
# KeepAlive: Whether or not to allow persistent connections (more than 
# one request per connection). Set to "Off" to deactivate. 
# 
KeepAlive On 

# 
# MaxKeepAliveRequests: The maximum number of requests to allow 
# during a persistent connection. Set to 0 to allow an unlimited amount. 
# We recommend you leave this number high, for maximum performance. 
# 
MaxKeepAliveRequests 0 

# 
# KeepAliveTimeout: Number of seconds to wait for the next request from the 
# same client on the same connection. 
# 
KeepAliveTimeout 5 
+0

什麼是Apache的日誌? – rkosegi 2013-04-11 09:22:35

+0

有沒有進入到這個話題:/ – bbholzbb 2013-04-11 09:24:43

+0

如果你呼應test.txt的內容,會發生什麼? – bestprogrammerintheworld 2013-04-11 09:35:43

回答

0

在php.ini

+0

不,它沒有幫助。同樣的錯誤再次! – bbholzbb 2013-04-11 09:30:44

0

請不是file_get_contents()返回一個字符串整個文件的搜索max_execution_time

while-loop迭代只要$ content不等於只有字符串「true」。如果你有一個只返回內容「true」的文件,那麼它將退出循環,否則不會。

我猜你試圖做這樣的事情:

<?php 
    $content =""; 
    while(!strstr($content,"true")) { 
     sleep(1); 
     $content = file_get_contents("test.txt"); 
    } 
    echo "now"; 

?> 

的代碼實際上並沒有做創建用於檢查一個文件中的字符串的unnessecary環路旁邊什麼。

0

在php.ini中增加max_execution_time的值& Apache上有一個max_input_time設置,用於定義他們將等待發布數據的時間長度,而不考慮大小。如果這個時間用完,連接關閉甚至沒有觸及php。

0

文件中獲取內容1個字符串返回的一切。我認爲你想要做的是循環遍歷線並搜索是否在該行中找到「true」,找到真正的位置,然後在返回之前返回所有內容?