用 PHP 理解 Apache 上的“408 请求超时" [英] Understanding “408 Request Timeout” on Apache with PHP

查看:69
本文介绍了用 PHP 理解 Apache 上的“408 请求超时"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题描述 - Apache 日志

我在 Apache 日志文件中发现了与此类似的项目:

I found items similar to this one in the Apache log file:

166.147.68.243 [24/Feb/2013:06:06:25 -0500] 19 web-site.com "-" 408 - "-"

我有自定义日志格式,408 在这里代表状态.日志格式为:

I’ve got custom log format and 408 here stands for status. The log format is:

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"

这就是为什么 408 错误行对我来说很奇怪.没有记录请求,我不知道应该优化什么.

This is why 408 error lines look strange to me. No request is logged and I have no idea on what should be optimized.

问题

如何解决这个问题?我应该收集哪些额外的信息或日志?什么可能导致问题?这是服务器上的问题吗?或者这绝对是网络连接问题?

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?

我之所以要解决这个问题,是因为我们的客户抱怨他的手机出现了 408 错误.我在日志文件中发现了很多记录,但我不得不承认我不知道该怎么做.

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.

我自己的研究

这里已经有几个关于这个主题的问题.但人要具体得多.就像他们讨论某些特定客户端软件和脚本的问题一样.在这里,我在 iPhone 上打开某个页面时遇到了错误.

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.

例如在HTTP, 408 Request timeout中,建议做GET请求在 POST 之前.如果我有自定义客户端,我可以这样做.但是我无法控制用户浏览器的行为.

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.

猜一猜

在互联网上搜索并思考这个问题时,我发现了 https://serverfault.com/questions/383290/too-many-408-error-codes-in-access-log

When searching the Internet and thinking about the issue I found https://serverfault.com/questions/383290/too-many-408-error-codes-in-access-log

建议更新Timeout 配置参数恢复为默认值.

The suggestion is to update the Timeout config parameter back to its default value.

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

我首先尝试了值 30,因为我认为 30 秒应该足够了.但即使有 300 秒的默认值,我仍然在日志中看到错误. 我在写这篇文章时做了 tail -f 并且得到了超过 10 行几分钟.

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 -f when I was writing this text and got more then 10 lines in a few minutes.

对我来说,这看起来不是一个完整的解决方案.

To me this does not look a complete solution.

推荐答案

在对该主题进行了一些研究后,我得出了以下答案.它由我们的首席开发人员提供,我认为它很好地解释了该主题.

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.

这些错误是完全正常的.它们不是更大问题的迹象,而是让 Apache 打开的时间超过允许时间的正常连接.

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 保持打开状态.Apache 的回应是适当地关闭了他.

For example, client's queries running them over and over kept Apache open. Apache responded by shutting him down appropriately.

如果没有,那么少数人就可以接管我们的服务器,而不允许其他任何人连接.

If it hadn't, than a handful of people could take over our server and not allow anyone else to connect.

大多数情况下,这些错误来自寻找漏洞的系统,您可以通过打开 telnet 会话并将其保持打开状态来重新创建它.

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.

同时,tail -f 访问日志,在 X 时间 (KeepAliveTimeout) 内,您将看到具有相同错误代码的 IP 弹出窗口.

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.

在 Apache 1.3 的时代,这个错误很常见,但后来 2.2 出来了,他们把它删除了,直到我们有足够多的人要求归还它,因为它让我们知道有多少人在保持开放端口,而不是请求实际资源等

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.

我认为除了确保将 Timeout 设置为我在原始问题中描述的某个合理值之外,不应做其他任何事情.

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.

这篇关于用 PHP 理解 Apache 上的“408 请求超时"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆