如何在PHP错误时设置Apache HTTP 503错误代码而不是HTTP 500 [英] How to set Apache HTTP 503 error code instead of HTTP 500 on PHP error
问题描述
P.S。如果可能的话,
将能够将Retry-After添加到50倍的错误代码中。
欢呼,
/ Marcin
我假设你是指PHP的新(自5.2.4)默认行为如果发生错误则抛出500,并且没有其他输出。
AFAIK,该行为是硬编码的,您将无法更改,而不改变PHP本身。
最简单的方法可能是设置自定义错误处理程序,以及有一个为你扔503:
标题(HTTP / 1.1 503服务不可用);
echo---这里的错误信息-----;
die();
any ideas how to replace Apache HTTP 500 (Internal Server Error) error by HTTP 503 (Service Unavailable) on PHP error once PHP error displaying is off? This is much better option to inform spiders to back to the site soon...
P.S. would be great to be able to append Retry-After to the 50x error codes if possible...
cheers, /Marcin
I assume you are referring to PHP's new (since 5.2.4) default behaviour of throwing a 500 if an error occurs, and no other output is being made.
AFAIK, that behaviour is hard-coded, you won't be able to change that without changing PHP itself.
The easiest way may be setting up a custom error handler, and having that throw a 503 for you:
header("HTTP/1.1 503 Service Unavailable");
echo "--- error message here -----";
die();
这篇关于如何在PHP错误时设置Apache HTTP 503错误代码而不是HTTP 500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!