PHP Error Reporting Production vs Development
Asked Answered
A

2

14

What is best practice when setting error reporting on development and production applications? At the moment I have the following:

// development
error_reporting(E_ALL);

// production
ini_set('display_errors', 0);
ini_set('log_errors', 1);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
Abreact answered 30/5, 2018 at 10:50 Comment(4)
My opinion - dev it to have 0 errors and set error_reporting to off on production unless you need it for debugNorite
Disable display_errors in productionRickirickie
I've updated my question to confirm that display errors was off and log errors was on for live.Abreact
it's better turning display_errors off completely in any environment. Sometimes an error will cause headers to be sent too early, borking your script completely! Tail the log!Pastorship
S
28

Quoting the php-production.ini that should have come bundled with your PHP:

; 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.

and further

; 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

Since you asked for best practise, I suggest you go with that.

Scribe answered 30/5, 2018 at 11:8 Comment(0)
P
3

For the best error logging experience, set error_reporting to -1 (absolutely everything), turn display_errors off, and set a custom error_log.

Then in the terminal, type tail -f /path/to/error_log. Your notices, warnings and errors will now scroll past in real time, without distorting your web page's display.

It's always worth logging everything. In any environment.

Pastorship answered 30/5, 2018 at 10:54 Comment(2)
I had to work on a site that had so many notice errors that it was tricky to spot the /real/ errors. Also for some reason, one request was throwing a 500 error when logging all errors.Abreact
most notices just need simple fixes like isset() checks. And fixing a notice in a loop can drastically reduce the error log. Everything is an error! Get rid of them all! An empty log is a site that does what it's supposed to!Pastorship

© 2022 - 2024 — McMap. All rights reserved.