views:

965

answers:

3

I am getting the following error:

mysql_connect(): Too many connections

It has completely shut down my site, which has been running seamlessly for several years.

Note: I have shared hosting with GoDaddy.

How do I fix this?

ALSO: is there a way to close all connections and restart when on a shared hosting plan?

+2  A: 

Do you close your connection when you're done with them? Are you using some type of connection pooling? Sounds like you're opening connections and not closing them.

EDIT: Already answered by Quassnoi. In the case it is a DDoS, and you're using shared hosting, you may be left with just contacting your host and working it out with them. Unfortunately this is a risk when you don't have control of your whole system.

CookieOfFortune
so, at the risk of looking like a complete idiot...everywhere i've read says that php closes connections at the end of the script? other then that, im just using your typical mysql_connect()
johnnietheblack
Hmmm... you might have to try manually closing connections you don't need? What's the scale of your operation? Quassnoi might be right if you're not making an excessive number of connections.
CookieOfFortune
yeah, its not a small site...kinda sucks...and i dont have access to PhpMyAdmin with this problem, and GoDaddy has my hands tied :(
johnnietheblack
You should consider switching to a new host. Go Daddy has made political contributions to opponents of Net Neutrality, and they have also wrongfully shutdown sites like seclist.org and ratemycop.com. My experiences with DreamHost have been good, and they're less sketchy as a company.
Calvin
A: 

Consider using mysql_pconnect(). Your host may have adding some sort of throttling for connections. Like a maximum of 100 per 20 minutes or something weird.

Matt
-1. You would then be wasting a lot of connections on Apache children that are not opening the same database, or tables.
Alister Bulman
+2  A: 

Most probably, you have been a subject of a DDoS attack.

People on this forum complain on exactly same thing with exactly same provider.

The answer is this:

VB told me it was a DOS attack - here is their message:

This is not an 'exploit'. This is a DoS attack (Denial of Service). Unfortunately there is nothing we can do about this. DoS attacks can only be fought at the server or router level, and this is the responsibility of your host. Instead of doing this they have decided to take the easy way out and suspend your account.

If you cannot get them to take this seriously, then you should look for another host. Sorry for the bad news.

A possible workaround can be this: if your connection fails with mysql_connect(): Too many connections, you don't quit, but instead sleep() for half a second and try to connect again, and exit only when 10 attempts fail.

It's not a solution, it's a workaround.

This of course will delay your page loading, but it's better than an ugly too many connections message.

You also can come with a some kind of a method which tells bots and browsers apart.

Like, set a salted SHA1 cookie, redirect to the same page and then check that cookie and connect to MySQL only if the user agent had passed the test.

Quassnoi
so then what do i do?
johnnietheblack
thanks for all the help...im assuming thats what it was...all the sudden it popped back up.
johnnietheblack