Thanks for your thoughts about Wordfence.
Unfortunately, you are misunderstanding the error message. When you see a “Commands out of sync” database error in your logs there are often other plugins getting the same error as well. The issue happens because some plugins, including Wordfence, use PHP’s “shutdown handler” to run some code after the rest of a database request has finished. If the database connection is lost during a request, this shutdown code still runs and reconnects to the database, which isn’t in a state where queries can be run. Such states include the database being unavailable due to shutting down, or a query limitation set by the hosting provider is reached.
The “Commands out of sync” errors are not the actual cause of a problem, but rather side-effects of the database getting disconnected. When this error is logged, it’s because something else already failed, but it isn’t visible in PHP’s error log.
If you have WP-CLI you can run a query like:
wp db query ‘\s’
…which should show you the database server’s uptime. The same can be done on the MySQL command line by just typing \s. In a couple of cases reported to us where users had the access to do this, they did find that the database server had recently restarted when they saw these errors. Generally, your hosting provider will need to look into the problem with the database. If they are willing to send us logs, including mysql/mariadb logs and the syslog, we may be able to help determine the cause. Open a forum support request if the hosting provider does and we can give you information on where to send the logs.
Thanks,
Mia