我希望与我的客户端建立连接。如果文件包含单词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, sh@lorchs.de 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 :(得分:0)
在php.ini中搜索max_execution_time
答案 1 :(得分:0)
请注意,file_get_contents()
不会返回整个文件的字符串。
while循环就会迭代。如果你有一个只返回内容“true”的文件,那么它将退出循环,否则不会。
我猜你正试图做这样的事情:
<?php
$content ="";
while(!strstr($content,"true")) {
sleep(1);
$content = file_get_contents("test.txt");
}
echo "now";
?>
除了为检查文件中的字符串创建一个不必要的循环外,代码实际上没有做任何事情。
答案 2 :(得分:0)
在php.ini&amp;中增加max_execution_time的值Apache上有一个设置max_input_time,用于定义等待发布数据的时间长度,无论大小如何。如果这个时间用完了,连接就会关闭,甚至没有触及php。
答案 3 :(得分:0)
文件获取内容返回1个字符串中的所有内容。我认为你想要做的是循环遍历线并搜索是否在该行中找到“true”,找到true的位置然后在此之前返回所有内容?