Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to suppress php errors on production servers

Tags:

What is the best method of hiding php errors from being displayed on the browser?

Would it be to use the following:

ini_set("display_errors", 1); 

Any best practice tips would be appreciated as well!

I am logging the errors, I just want to make sure that setting the display_errors value to off (or 0) will not prevent errors from being logged.

like image 773
Matt Avatar asked Dec 01 '08 20:12

Matt


People also ask

How do I supress php errors?

PHP allows you to selectively suppress error reporting when you think it might occur with the @ syntax. Thus, if you want to open a file that may not exist and suppress any errors that arise, you can use this: $fp = @fopen($file, $mode);

How do I hide php warnings and notices in WordPress?

Either way, you're looking for the “WP_DEBUG” portion of the wp-config. php file. Click the “Save Changes” button in the top right. Once the file is saved, this will disable the PHP warnings in WordPress.

How do I hide php errors in WordPress?

Turning off PHP Errors in WordPressini_set ( 'error_reporting' , E_ALL ); define( 'WP_DEBUG' , false); define( 'WP_DEBUG_DISPLAY' , false); Don't forget to save your changes and upload your wp-config.


2 Answers

The best way is to log your errors instead of displaying or ignoring them.

This example will log the errors to syslog instead of displaying them in the browser.

ini_set("display_errors", 0); ini_set("log_errors", 1);  //Define where do you want the log to go, syslog or a file of your liking with ini_set("error_log", "syslog"); // or ini_set("error_log", "/path/to/syslog/file"); 
like image 123
Vinko Vrsalovic Avatar answered Oct 01 '22 02:10

Vinko Vrsalovic


Assuming you are in control of the php.ini file, you can make these changes globally inside that file instead of having the ini_set code laying around in all your php files (which you might forget to put in one of your files one day, which could be bad in production).

like image 22
grepsedawk Avatar answered Oct 01 '22 01:10

grepsedawk