如何阻止 PHP 记录 PHP 通知错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2099147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to stop PHP from logging PHP Notice errors
提问by echo
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):
我试图不记录正在写入我服务器上的错误日志文件的通知错误。我试过(在我的顶部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.
但我仍然在上述错误日志文件中收到 PHP 通知错误。
I'm on a shared hosting environment, so I can't edit my php.inifile.
我在共享主机环境中,所以我无法编辑我的php.ini文件。
phpinfo()tells me:
phpinfo()告诉我:
- Version 5.2.12
- error_reporting 6143
- error_log error_log
- safe_mode Off
回答by echo
If you're on an Apache server, try setting the value in a .htaccess file. The general format is:
如果您使用的是 Apache 服务器,请尝试在 .htaccess 文件中设置该值。一般格式为:
php_flag log_errors on
php_value error_log /path/to/error.log
php_value error_reporting integer
where integeris the value you get from running something like:
integer您从运行以下内容中获得的价值在哪里:
echo E_ALL & ~E_NOTICE; // prints 30711
More info here:
更多信息在这里:
http://perishablepress.com/press/2008/01/14/advanced-php-error-handling-via-htaccess/
http://perishablepress.com/press/2008/01/14/advanced-php-error-handling-via-htaccess/
回答by Alix Axel
Try doing:
尝试做:
error_reporting(E_ALL & ~E_NOTICE);
The error_reporting()directive will always works (PHP_INI_ALL).
该error_reporting()指令将始终有效 ( 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:
做error_reporting(0);然后做这个:
var_dump(error_reporting());
What is the output?
输出是什么?
回答by Bob Fanger
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);
回答by z3cko
you can change the error reporting level to something different
您可以将错误报告级别更改为不同的级别
error_reporting(E_ERROR | E_WARNING | E_PARSE);
错误报告(E_ERROR | E_WARNING | E_PARSE);
see http://www.php.net/manual/en/function.error-reporting.phpfor more information
有关更多信息,请参阅http://www.php.net/manual/en/function.error-reporting.php

