【问题标题】:Apache Fall Back When PHP FailsPHP 失败时 Apache 回退
【发布时间】:2010-09-08 21:17:49
【问题描述】:

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

谢谢。

【问题讨论】:

    标签: php apache configuration


    【解决方案1】:

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

    ErrorDocument 500 /500error.html

    您还可以在 apaches documentation site 上阅读有关错误处理程序的信息

    【讨论】:

      【解决方案2】:

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

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

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

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

      【讨论】:

        【解决方案3】:

        真正的问题是 PHP 致命错误不会导致 Apache 返回 500 代码。除了E_FATALE_PARSE 之外的错误可以用set_error_handler() 来处理。

        【讨论】:

          【解决方案4】:

          有两种使用 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 文件中的错误。

          【讨论】:

            猜你喜欢
            • 2017-03-07
            • 2017-12-05
            • 2015-07-20
            • 2021-12-14
            • 1970-01-01
            • 2013-06-27
            • 2012-07-03
            • 1970-01-01
            • 2011-05-29
            相关资源
            最近更新 更多