PHP 错误报告生产与开发

PHP Error Reporting Production vs Development

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

// development
error_reporting(E_ALL);

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

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

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

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

引用本应与您的 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

既然你问的是最佳实践,我建议你去做。