MySQL Server Intermittent Connection Problem

mysql

#1

One of our sites runs signage using WordPress and the website keeps timing out with the following error:

Connection timed out
Error establishing a database connection

This is a problem, since the content has an auto-refresh tag that refreshes every 60 seconds to update, using HTML5. The sign needs to update with that frequency. If this error message shows, the sign stops refreshing.

Our WordPress Debug logs show the following error repeatedly:
[15-Apr-2019 23:40:44 UTC] PHP Warning: mysqli_real_connect(): (HY000/2002): Connection timed out in /home/site/signage/wp-includes/wp-db.php on line 1612

The frustrating part is that this issue happens intermittently, however, it does happen on all browsers and signage devices, eventually.

I’ve submitted a ticket with DreamHost, but it appears they haven’t been able to recreate the issue yet, and haven’t gotten back to me just yet.

Any thoughts?


#2

I don’t have a solution to the DB time-out, but one workaround might be to add a custom DB error page (wp-content/db-error.php), which would also have the HTML auto-refresh tag to force a reload a few seconds after the error. Details about db-error.php at:

https://developer.wordpress.org/reference/functions/dead_db/

Longer term, the HTML auto-refresh mechanism will have to deal with a variety of possible errors (404, 500, DB connection, etc). Although errors are normally very rare, they will eventaully happen and one needs to plan for them.

One could add custom error pages for all the errors, or possibly use .htaccess rules to add HTTP Refresh headers to all requests. A more robust solution might be to use Javascript (AJAX, etc) to reload the page, so that errors can be detected early and retried.


#3

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.