No such file or directory
That’s kind of odd since mysqli_real_connect() accepts no file paths nor accesses any files. As its name suggests, it’s trying to connect to your DB server. I think the file error is because WP is trying to log an error to a file it doesn’t have permission to write to. The root cause is the connection attempt failed. All remaining messages are only side effects of the root cause.
Apparently your DB connection credentials are correct since they work some of the time. Intermittent connection faults could indicate the DB server is overloaded. In any case, intermittent connection failures are an issue with the server’s configuration and you’ll need your host’s assistance to resolve it.
IME having the host move your site to a different server will frequently resolve similar problems.
@bcworkz Thank you so much for the explanation.
As this website is fairly big, I don’ think we can move it easily to another host. However, can you please explain more about this line your wrote?
I think the file error is because WP is trying to log an error to a file it doesn’t have permission to write to.
Can disabling the log completely fix the issue?
This is what I have in wp-config.php for debugging
define(‘WP_ALLOW_REPAIR’, false);
define(‘DISABLE_WP_CRON’, true);
// log PHP errors
@ini_set(‘log_errors’,’On’); // enable or disable PHP error logging (use ‘On’ or ‘Off’)
@ini_set(‘display_errors’,’Off’); // enable or disable public display of errors (use ‘On’ or ‘Off’)
@ini_set(‘error_log’,’/var/www/html/site/php-errors.log’); // path to server-writable log file
//another way to log
define( ‘WP_DEBUG’, true );
//define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_DEBUG_DISPLAY’, false );
define(‘WP_MEMORY_LIMIT’, ‘256M’);
//define(‘WP_MEMORY_LIMIT’, ‘256M’);
//define(‘DISABLE_WP_CRON’, true);
//define(‘CONCATENATE_SCRIPTS’, false);
/* That’s all, stop editing! Happy publishing. / /* Absolute path to the WordPress directory. / if ( ! defined( ‘ABSPATH’ ) ) { define( ‘ABSPATH’, dirname( FILE ) . ‘/’ ); } /* Sets up WordPress vars and included files. */
require_once( ABSPATH . ‘wp-settings.php’ );
Disabling the error log will only change the error messages you see on screen, if any. It will not resolve whatever the root cause is. My comment about not being able to write to the error log was only explaining why the error message was there. It doesn’t explain what causes the connection failure.
The other messages about wpdb being used incorrectly are also because the connection failed. Resolve the connection problem and the messages will go away. It’s somewhat common for error messages to be misleading. They reflect the immediate issue encountered. The issue encountered is not necessarily the root cause of the problem.
Intermittent problems are almost always related to server configuration and not WP itself. You’ll likely need your host’s assistance to resolve this. If they also have trouble isolating the problem, I recommend asking them if they could move your site to a different server. I wasn’t suggesting changing hosts, only servers. You’d only change hosts if you’re distinctly unhappy with the service provided.