如何在 PHP 错误上设置 Apache HTTP 503 错误代码而不是 HTTP 500 [英] How to set Apache HTTP 503 error code instead of HTTP 500 on PHP error

查看:53
本文介绍了如何在 PHP 错误上设置 Apache HTTP 503 错误代码而不是 HTTP 500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦 PHP 错误显示关闭,如何将 Apache HTTP 500(内部服务器错误)错误替换为 PHP 错误上的 HTTP 503(服务不可用)?这是通知蜘蛛尽快返回站点的更好选择...

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...

附言如果可能的话,能够将 Retry-After 附加到 50x 错误代码会很棒...

P.S. would be great to be able to append Retry-After to the 50x error codes if possible...

干杯,/马辛

推荐答案

我假设您指的是 PHP 的新(自 5.2.4 起)默认行为 如果发生错误,则抛出 500,并且没有其他输出.

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,这种行为是硬编码的,如果不改变 PHP 本身,你将无法改变它.

AFAIK, that behaviour is hard-coded, you won't be able to change that without changing PHP itself.

最简单的方法可能是设置一个自定义错误处理程序,然后为您抛出 503:

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屋!

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