状态 503:是否需要 "Retry-After"?

Status 503: is "Retry-After" necessary?

我正在向我的 php 脚本添加 503 header 语句。在我见过的所有例子中,这之后是一些变体:

header('Retry-After: 300');

是否需要包含"Retry-After"语句?我宁愿不要。

不,没有必要。

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

"The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response."

如果知道,延迟的长度可以在 Retry-After header 中指示。

Retry-After header 是您可以用来告诉客户退缩的措施。

处理大量流量的服务通常具有循环检测逻辑,以检测过于频繁地调用昂贵 API 的客户端。例如,行为不当的客户端会每隔几秒从身份验证服务请求身份验证令牌,而不是缓存令牌直到它们过期。

当然,不能保证客户端会遵守 retry-after 规则,在这种情况下,您可以更严格地限制它们。