0

We're getting a Headers and client library minor version mismatch message and we have a path to resolving the actual warning, but for now we need to suppress it.

But! We need to keep all other warnings.

So, is there a way to suppress this single error message?

Nathan J.B.
  • 10,215
  • 3
  • 33
  • 41
  • FYI - I know I can use `@` to suppress errors from a single line of code, but that would require suppressing ALL MySQL errors, not just this one. – Nathan J.B. Nov 13 '15 at 21:58
  • nope. can't be done short of recompiling php. there isn't fine-grained enough control of warnings/errors to disable one specific error, only specific TYPES of errors. – Marc B Nov 13 '15 at 21:59
  • 2
    Well, you can set up [your own error handler](http://php.net/manual/en/function.set-error-handler.php) – and if that particular warning occurs, ignore/absorb it, and for everything else output and/or log the interesting parts of the error yourself. If you don’t want it to affect your overall application too much, you can do so just before the warning occurs, and [restore PHP’s original error handler](http://php.net/manual/en/function.restore-error-handler.php) afterwards. – CBroe Nov 13 '15 at 22:06

2 Answers2

1

You can use set_error_handler and check for the specific message, then just return false in cases where you want the use default error handling

E.G

set_error_handler(function ($errno, $errstr, $errfile, $errline) {
    if (false === strpos($errstr, 'Headers and client library minor version mismatch')) {
        return false;
    }
});
Pierre
  • 1,553
  • 12
  • 22
0

If the error only occurs once in a request lifecycle (i.e. when connecting to the database, a temporary custom error handler could silence the warning if it matches a condition.

Alternatively ship logs through a processor like Kibana for realtime filtering and graphing.

Community
  • 1
  • 1
NoChecksum
  • 1,206
  • 1
  • 14
  • 31