Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Error Reporting Production vs Development

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);
like image 622
xylar Avatar asked May 30 '18 10:05

xylar


People also ask

What are the various forms of error reporting in PHP?

error_reporting(E_ALL); error_reporting(-1); ini_set('error_reporting', E_ALL); All of the above lines serve the same purpose i.e. show all the errors. E_ALL is the most widely used function among all others by developers to display error messages as it is more comprehensible and intelligible.

Does PHP support error reporting?

The error reporting function is a built-in PHP function that allows developers to control which and how many errors will be shown in the application. Remember, the PHP ini configuration has an error_reporting directive that will be set by this function during runtime. error_reporting(0);

How many levels of error reporting are there in PHP?

How many error levels are available in PHP? There are a whopping 16 error levels in PHP 5. These errors represent the category and sometimes severity of an error in PHP.

What is the use of error reporting function in PHP?

The error_reporting() function specifies which errors are reported. PHP has many levels of errors, and using this function sets that level for the current script.


1 Answers

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.

like image 67
Gordon Avatar answered Oct 03 '22 12:10

Gordon