AJJ
AJJ

Reputation: 7701

Prevent calls to error_reporting() and/or ini_set('display_errors', 'On') from overriding php.ini settings

I had this setting in my php.ini file:

error_reporting = E_ERROR|E_PARSE|E_CORE_ERROR|E_COMPILE_ERROR

But I was still receiving thousands of NOTICE and WARNING entries in the error log every minute. I of course realize I would better deal with those errors, but this is not my code and I am not being paid to do that, I just needed to get rid of those fat error_log files (Gbs per day).

I searched through the code and removed all error_reporting() calls, and that did the trick but, is there a way to disallow error_reporting() from overriding php.ini settings?

Could I also prevent calls to ini_set('display_errors') from overriding php.ini settings?

Upvotes: 3

Views: 4195

Answers (3)

Charles
Charles

Reputation: 51411

is there a way to disallow error_reporting() from overriding php.ini settings?

Maybe.

If you're using mod_php under Apache (or FastCGI via FPM), you can use php_admin_value and php_admin_flag to force certain INI settings in such a way that ini_set will be unable to override.

Unfortunately I don't know of a way to neuter error_reporting other than disable_functions -- but this will throw a PHP Warning every time it's used.

(As a side note, I find it curious that a developer would set an error reporting level in production and still be producing such a high volume of logs.)

Upvotes: 3

Marc B
Marc B

Reputation: 360802

You could try the disable_functions php.ini setting and turn off error_reporting() and ini_set(). But that COMPLETELY disables them, so if you need to change settings other than error_reporting at runtime, you'd be SOL.

Upvotes: 2

George Cummins
George Cummins

Reputation: 28936

According to the following pages, the PHP engine sets when and where a configuration option can be set. There is no way to prevent it programmatically:

http://www.php.net/manual/en/configuration.changes.modes.php http://php.net/manual/en/errorfunc.configuration.php

Upvotes: 0

Related Questions