I have a website I built from scratch some years ago using html and php, and with a MySQL database. As of two or three months ago, intermittently when a page is loaded, it hangs up for 60 seconds and then reports a database connection timeout. This is a fatal error where the page exits, but if I reload the page manually, it loads again, usually successfully. This problem behavior occurs somewhere between the 2nd and 20th times that any script using the database is loaded. It makes the site very difficult to use.
The hosting company has been very helpful. For example, they told me the site is not exceeding the allowable loading limits for shared hosting. They even transferred the database to a different MySQL server, which indicates the problem is not in that server. And they have adjusted parameters in the php.ini file to allow scripts plenty of freedom.
I’ve been watching the apache error log. At first I noticed numerous crawlers interrogating the site, and they also were experiencing the database connection timeout. I subsequently eliminated most crawlers by either disallowing them in the robots.txt file, or denying them access via the .htaccess file.
The site is now very quiet. So I wrote a simple php script (no CSS, etc.) that does nothing except connect to the database and then immediately close the connection. However, when I reload it repeatedly, it intermittently triggers the connection timeout, similar to what I’ve described.
I believe the 60 seconds timeout is the default for MySQL connect Of course, it should not need 60 seconds. And generally there is nothing else going on than my reloading the test script every few seconds.
I would much appreciate any thoughts about this issue. For example, might it be that there is a virus consuming the MySQL bandwidth? (Of course, one might then ask why the virus script itself doesn’t experience the timeout issue.)
I have two other similarly constructed websites at the same hosting company that do not exhibit this problem.
Thanks for any ideas about what might be causing this. Or how best to go about locating the cause.