用 PHP 理解 Apache 上的“408 请求超时”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/15090897/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Understanding “408 Request Timeout” on Apache with PHP
提问by Victor Smirnov
Issue description - Apache logs
问题描述 - Apache 日志
I found items similar to this one in the Apache log file:
我在 Apache 日志文件中发现了与此类似的项目:
166.147.68.243 [24/Feb/2013:06:06:25 -0500] 19 web-site.com "-" 408 - "-"
I've got custom log format and 408here stands for status. The log format is:
我有自定义日志格式,408这里代表状态。日志格式为:
LogFormat "%h %t %D %V \"%r\" %>s %b \"%{User-agent}i\"" detailed
And normally the line in the log file looks like
通常日志文件中的行看起来像
184.73.232.108 [26/Feb/2013:08:38:16 -0500] 30677 www.site.com "GET /api/search... HTTP/1.1" 200 205 "Zend_Http_Client"
This is why 408 error lines look strange to me. No request is logged and I have no idea on what should be optimized.
这就是为什么 408 错误行对我来说看起来很奇怪。没有记录请求,我不知道应该优化什么。
Questions
问题
How to tackle the issue? What additional information or logs should I gather? What might cause the issue? Is this something wrong on the server? Or is this absolutely a network connectivity problem?
如何解决问题?我应该收集哪些额外的信息或日志?什么可能导致问题?这是服务器上的问题吗?或者这绝对是网络连接问题?
I'm addressing this because our customer complained that he has got 408 error on his mobile phone. I found many records in the log file but I have to admit I don't know what to do with this.
我正在解决这个问题,因为我们的客户抱怨他的手机出现 408 错误。我在日志文件中发现了很多记录,但我不得不承认我不知道该怎么做。
My own research
我自己的研究
There are several questions on this subject already here. But people are much more specific. Like they discus issues with some specific client software and scripts. Here I just got the error when opening some page on iPhone.
这里已经有关于这个主题的几个问题。但人要具体得多。就像他们讨论某些特定客户端软件和脚本的问题一样。在这里,我在 iPhone 上打开某个页面时遇到了错误。
For example in HTTP, 408 Request timeout, it is suggested to do the GET request before POST. If I have custom client I can do this. But I can not control the behavior of the user's browser.
例如在HTTP 中, 408 Request timeout,建议在 POST 之前做 GET 请求。如果我有自定义客户端,我可以这样做。但我无法控制用户浏览器的行为。
Guess #1
猜一猜
When searching the Internet and thinking about the issue I found https://serverfault.com/questions/383290/too-many-408-error-codes-in-access-log
在网上搜索并思考这个问题时,我发现了https://serverfault.com/questions/383290/too-many-408-error-codes-in-access-log
The suggestion is to update the Timeoutconfig parameter back to its default value.
建议是将Timeoutconfig 参数更新回其默认值。
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300
I tried the value 30 first because I thought 30 seconds should be enough. But even with 300 seconds default value, I continue to get the errors in the log.I did tail -fwhen I was writing this text and got more then 10 lines in a few minutes.
我首先尝试了值 30,因为我认为 30 秒应该足够了。但即使使用 300 秒的默认值,我仍然在日志中收到错误消息。我tail -f在写这篇文章的时候做了,几分钟内就写了 10 多行。
To me this does not look a complete solution.
对我来说,这看起来不是一个完整的解决方案。
采纳答案by Victor Smirnov
After some studies on the subject I came to the following answer. It is provided by our lead developer and I think it gives good explanation of the subject.
在对该主题进行了一些研究后,我得出了以下答案。它由我们的首席开发人员提供,我认为它很好地解释了这个主题。
These errors are perfectly normal. They aren't a sign of a larger issue, but normal connections that are holding Apache open for longer than allowed.
这些错误是完全正常的。它们不是更大问题的迹象,而是使 Apache 打开的时间超过允许时间的正常连接。
For example, client's queries running them over and over kept Apache open. Apache responded by shutting him down appropriately.
例如,反复运行它们的客户端查询使 Apache 保持打开状态。Apache 的回应是适当地关闭了他。
If it hadn't, than a handful of people could take over our server and not allow anyone else to connect.
如果没有,那么少数人就可以接管我们的服务器,不允许其他人连接。
Most often these errors are coming from systems looking for exploits, and you can recreate it by opening a telnet session and leaving it open.
大多数情况下,这些错误来自寻找漏洞的系统,您可以通过打开 telnet 会话并将其保持打开状态来重新创建它。
At the same time, tail -f the access log, and within X time (KeepAliveTimeout) you'll see your IP popup with the same error codes.
同时,tail -f 访问日志,在 X 时间 (KeepAliveTimeout) 内,您将看到具有相同错误代码的 IP 弹出窗口。
Back in the days of Apache 1.3, this error was common, but then 2.2 came out and they had it removed until enough of us asked for it to be returned since it give us ideas on how many people are holding open just the port, and not requesting an actual resource, etc.
在 Apache 1.3 的时代,这个错误很常见,但后来 2.2 出现了,他们将其删除,直到我们有足够多的人要求退回它,因为它让我们知道有多少人只打开端口,并且不请求实际资源等。
I think nothing else should be done here except to make sure to set Timeout to some reasonable value as I have described in original question.
我认为除了确保将 Timeout 设置为我在原始问题中描述的某个合理值之外,这里不应该做任何其他事情。
回答by Ron
Actually a lot of 408 messages in apache logs are a result pre-fetching mechanism in modern browsers. From looking in apache logs in the last 3 years the amount of 408 errors had more than doubled for the same traffic.
实际上,apache 日志中的很多 408 消息是现代浏览器中的结果预取机制。通过查看过去 3 年的 apache 日志,相同流量的 408 错误数量增加了一倍多。
回答by M K
If there is a Proxy set up in Apache, and the back end is not responding in a timely fashion for some reason, the same 408 - - will be seen in the logs. Proxy timeouts are configured separately, that's why changing the Apache default timeout doesn't seem to do anything about those requests.
如果在 Apache 中设置了 Proxy,并且后端由于某种原因没有及时响应,则日志中将看到相同的 408 -- -- 。代理超时是单独配置的,这就是为什么更改 Apache 默认超时似乎对这些请求没有任何作用。

