4

我想知道是否有人知道配置 apache 以返回静态 HTML 页面的方法,它(Apache)是否能够确定 PHP 已经死了?这将为开发人员提供一个优雅的解决方案来显示错误页面,而不是(最坏的情况)应该执行的 PHP 页面的源代码。

谢谢。

4

4 回答 4

8

仅当未正确配置 apache 以处理 php 文件时,才会显示 PHP 源代码。也就是说,当尚未定义适当的处理程序时。

出现错误时,可以在 php.ini 上配置显示的内容,主要是 display_errors 变量。这应该在生产环境中设置为 off 和 log_errors 为 on。

如果 php 真的死了,apache 将返回适当的 HTTP 状态代码(通常是 500)以及 ErrorDocument 指令定义的页面。如果它没有死,而是陷入了一个循环,据我所知,你无能为力。

您可以为不同的错误代码指定不同的页面。

于 2008-09-15T09:30:30.330 回答
3

我假设这通常会导致 500 错误,您可以配置 apaches 500 处理程序以显示静态页面:

错误文档 500 /500error.html

您还可以在apaches 文档站点上阅读有关错误处理程序的信息

于 2008-09-15T09:27:33.957 回答
1

真正的问题是 PHP 致命错误不会导致 Apache 返回 500 代码。E_FATAL除了和之外的错误E_PARSE可以按照您喜欢的方式处理set_error_handler()

于 2008-09-15T13:14:48.917 回答
0

有两种使用 PHP 和 Apache 的方法。

1. Install PHP as an Apache module: this way the PHP execution is a thread inside the apache process. So if PHP execution fails, then Apache process fails too. there is no fallback strategy.

2. Install PHP as a CGI script handler: this way Apache will start a new PHP process for each request. If the PHP execution fails, then Apache will know that, and there might be a way to handle the error.

无论您安装 PHP 的方式如何,当 PHP 执行失败时,您都可以处理php.ini文件中的错误。

于 2008-09-15T19:31:30.417 回答