How to stop PHP from logging PHP Notice errors
I'm trying to not log notice errors, which are being written to an error log file on开发者_如何转开发 my server. I've tried (at the top of my index.php
):
ini_set('display_errors', 0);
error_reporting(E_ALL ^ E_NOTICE);
But I'm still getting PHP notice errors in said error log file.
I'm on a shared hosting environment, so I can't edit my php.ini
file.
phpinfo()
tells me:
- Version 5.2.12
- error_reporting 6143
- error_log error_log
- safe_mode Off
If you're on an Apache server, try setting the value in a .htaccess file. The general format is:
php_flag log_errors on
php_value error_log /path/to/error.log
php_value error_reporting integer
where integer
is the value you get from running something like:
echo E_ALL & ~E_NOTICE; // prints 30711
More info here:
http://perishablepress.com/press/2008/01/14/advanced-php-error-handling-via-htaccess/
Try doing:
error_reporting(E_ALL & ~E_NOTICE);
The error_reporting()
directive will always works (PHP_INI_ALL
).
Are you sure you're not including any library that changes your error reporting level?
Do error_reporting(0);
and then do this:
var_dump(error_reporting());
What is the output?
Are you getting Notice's or "USER" Notice's in your log?
To disable both use:
error_reporting(E_ALL & ~E_NOTICE & ~E_USER_NOTICE);
you can change the error reporting level to something different
error_reporting(E_ERROR | E_WARNING | E_PARSE);
see http://www.php.net/manual/en/function.error-reporting.php for more information
精彩评论