2013-04-11 68 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”,找到真正的位置,然后在返回之前返回所有内容?