Reputation: 152284
Wordpress is still using mysql_*
functions that are deprecated so Apache's error.log
file is swelling.
Is it possible somehow to ignore those specific warnings, so none of the mysql_*
deprecation errors for specific project will be shown ?
For example with some .htaccess
entry or PHP function.
Upvotes: 3
Views: 497
Reputation: 146588
Tweaking the error reporting level to hide E_DEPRECATED
stuff is probably not the best option because you'll lose the ability to see that information in your own code. And PHP does not offer enough granularity to filter out deprecated notices by function or library. Your only option, I'm afraid, is to write your own custom error handler.
(Disclaimer: I don't know whether WordPress implements a custom error handler as well. If it does, you'll have to be careful in order to not break it.)
It can be tricky if you've never done it before. Among other things, you need to ensure that you're obeying error_reporting
and the @
operator and you're aborting when you have to. Whatever, a simplified and not tested starting point could be this:
function ignore_mysql_deprecated($errno, $errstr, $errfile, $errline){
if( $errno===E_DEPRECATED && preg_match('/^mysql_.+\(\): The mysql extension is deprecated and will be removed in the future/U', $errstr) ){
// Ignore
return true;
}else{
// Call standard error handler
return false;
}
}
set_error_handler('ignore_mysql_deprecated');
If WordPress does not offer a standard mechanism to change the error handler, you can always plug this code in with the auto_prepend_file directive.
Tested solution
To mute any mysql_
calls in your project, we have to create a mute.php
file:
<?php
set_error_handler(function($errno, $errstr){
return strpos($errstr, 'mysql_') === 0;
}, E_DEPRECATED);
and add in apache configuration following line:
php_value auto_prepend_file mute.php
Upvotes: 4
Reputation: 147
You can hide all the deprecated warnings, but I don't think you can only avoid the mysql_* ones.
To disable it, use this in your PHP scripts (better if there's only mysql_* related code in this scripts so you don't lose any other deprecated information):
error_reporting(E_ALL ^ E_DEPRECATED);
Upvotes: 0