【问题标题】:PHP Error Reporting Production vs DevelopmentPHP 错误报告生产与开发
【发布时间】:2018-11-09 04:42:45
【问题描述】:

在开发和生产应用程序上设置错误报告时的最佳做法是什么?目前我有以下内容:

// development
error_reporting(E_ALL);

// production
ini_set('display_errors', 0);
ini_set('log_errors', 1);
error_reporting(E_ERROR | E_WARNING | E_PARSE);

【问题讨论】:

  • 我的意见 - 开发它有 0 个错误并将 error_reporting 设置为在生产中关闭,除非您需要它进行调试
  • 在生产中禁用display_errors
  • 我已经更新了我的问题,以确认显示错误已关闭并且日志错误已开启。
  • 最好在any环境中完全关闭display_errors。有时一个错误会导致过早发送标头,从而完全破坏您的脚本!跟踪日志!

标签: php error-reporting


【解决方案1】:

引用应该与您的 PHP 捆绑在一起的 php-production.ini

; PHP comes packaged with two INI files. One that is recommended to be used
; in production environments and one that is recommended to be used in
; development environments.

; php.ini-production contains settings which hold security, performance and
; best practices at its core. But please be aware, these settings may break
; compatibility with older or less security conscience applications. We
; recommending using the production ini in production and testing environments.

还有更多

; display_errors
;   Default Value: On
;   Development Value: On
;   Production Value: Off

; display_startup_errors
;   Default Value: Off
;   Development Value: On
;   Production Value: Off

; error_reporting
;   Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
;   Development Value: E_ALL
;   Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT

; html_errors
;   Default Value: On
;   Development Value: On
;   Production value: On

; log_errors
;   Default Value: Off
;   Development Value: On
;   Production Value: On

既然您要求最佳实践,我建议您这样做。

【讨论】:

    【解决方案2】:

    为了获得最佳的错误记录体验,请将error_reporting 设置为-1(绝对是所有内容),关闭display_errors关闭,然后设置自定义error_log

    然后在终端中输入tail -f /path/to/error_log。您的通知、警告和错误现在将实时滚动过去,而不会扭曲您的网页显示。

    记录一切总是值得的。在任何环境中。

    【讨论】:

    • 我不得不在一个有很多通知错误的网站上工作,以至于很难发现 /real/ 错误。同样出于某种原因,一个请求在记录所有错误时抛出了 500 错误。
    • 大多数通知只需要简单的修复,例如isset() 检查。并且在循环中修复通知可以大大减少错误日志。一切都是错误!摆脱他们!一个空的日志是一个做它应该做的事情的网站!
    猜你喜欢
    • 1970-01-01
    • 2018-11-04
    • 2013-04-17
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 2011-12-23
    • 2019-04-23
    • 1970-01-01
    相关资源
    最近更新 更多