WordPress Connection Timed Out Errors- debugging and repairing

Maybe you have an older, heavily modified wordpress site that has some outdated custom code, older plugins, and various other custom stuff that hasn’t been updated in some time. Your site occasionally stops responding for a while, often with an unable to establish database connection error. In Mysql you see a bunch of sleeping connections from your site, piling up until the connection limit is hit (often 100 connections) and then no more connections can be made- until all those sleeping connections finally time out (often set to 300 seconds) and clear, so the site can then start making new connections again. You try debugging this and can’t figure out why there are sleeping connections- WPDB and/or mysql client code all closes connections after use so how can they be left running? The main pages on the site are fast and responsive, so what is holding this open for so long anyway? And why the heck does it happen so infrequently, but frequently enough to be a pain?
Do this:
-Turn on error messages and logging to error file (will add details here, but there’s plenty info out there on how to do this)
-Let it run until these problems happen. Or, try to turn it on WHILE the problems are happening. The log file might get huge otherwise. Mine has a ton of deprecation warnings so it will grow rapidly.
-Once logging has run during the sleeping connection problem happening, open the log file and search for “fatal” to find fatal error messages.
-You should find a line with a fatal error message related to the database connection timing out after 300 seconds- this line will show you which php file caused the problem. In my case, it was an outdated plugin that I really didn’t need anymore, so I disabled it.

And now, back to semi-stable, or at least not crashing, wordpress bliss.

(I still hate wordpress though. well, php. I hate php. Yes! it’s horrible.)


I run a number of wordpress sites on a windows/IIS server, and many of these sites keep getting infected with some kind of trojan that seems to try to redirect traffic away to other sites, thus building “fake” backlinks and traffic. One of the files that seems to commonly show up is named zwi-cofg.php – it has a bunch of heavily disguised code inside it, so I haven’t dug into what it actually does yet- but out of all the infections I’ve seen, this file seems to be the most common. Googling it didn’t reveal anything so figured I would create a post and see if any others are discovering this file- and what you may have figured out about it? I’m also working to lock down my sites so they don’t continue to get infectected, but I’m beginning to think this is not an easy task when running php on windows servers. All the best practices I’ve seen don’t seem to go far enough. Continuing to investigate…