服务器过载时要发送的标头代码


What header code to send when the server is overloaded?

在php中,我想在进一步处理之前提供自定义的错误消息。

这是我所拥有的

if($overloaded==true){
    header('HTTP/1.0 503 Service Temporarily Unavailable');
    header('Status: 503 Service Temporarily Unavailable');
    header('Retry-After: 300');//300 seconds
    die();
}

来自: 如何使 php 页面返回 503 错误(或任何非 200 错误)

关于 503 服务在 w3.org 不可用:

  Note: The existence of the 503 status code does not imply that a
  server must use it when becoming overloaded. Some servers may wish
  to simply refuse the connection.

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

当我的服务器过载时,我应该如何处理 HTTP 请求?

如果你想准确一点,据我所知,你真的只有 2 个选择,那就是 503 或 500。

500 表示由于意外条件/原因无法满足请求。

503 表示由于服务器的临时过载或维护,您无法完成请求。

据我所知,错误 500 是一个非常普遍的错误,503 是最准确的,我强烈建议您使用超过 500 的错误。准确性永远是最好的。