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

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

问题描述

一旦PHP错误显示关闭,任何想法如何通过HTTP 503(服务不可用)对PHP错误代替Apache HTTP 500(内部服务器错误)错误?这是更好的选择,通知蜘蛛回到网站很快...



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

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