Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » [PHP] error message - too many connections

This thread is locked; no one can reply to it. rss feed Print
[PHP] error message - too many connections
count
Member #5,401
January 2005

From time to time I get this error message when I try to go to my site which has acces to my database. (all pages on my site):

Warning: mysql_connect(): Too many connections in /srv/www/htdocs/webxxx/html/xxx.php on line 6
database unavailable: :

Why is this happening? And is there anything I can do about it?
This is really annoying, because no visit to the site is possible during that time.

Thanks in advanve for your advice!

GullRaDriel
Member #3,861
September 2003
avatar

from http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html

A.2.6. Too many connections

If you get a Too many connections error when you try to connect to the mysqld server, this means that all available connections are in use by other clients.

The number of connections allowed is controlled by the max_connections system variable. Its default value is 100. If you need to support more connections, you should restart mysqld with a larger value for this variable.

mysqld actually allows max_connections+1 clients to connect. The extra connection is reserved for use by accounts that have the SUPER privilege. By granting the SUPER privilege to administrators and not to normal users (who should not need it), an administrator can connect to the server and use SHOW PROCESSLIST to diagnose problems even if the maximum number of unprivileged clients are connected. See Section 13.5.4.19, “SHOW PROCESSLIST Syntax”.

The maximum number of connections MySQL can support depends on the quality of the thread library on a given platform. Linux or Solaris should be able to support 500-1000 simultaneous connections, depending on how much RAM you have and what your clients are doing. Static Linux binaries provided by MySQL AB can support up to 4000 connections.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

count
Member #5,401
January 2005

Thank you.
I´m wondering how tjis can happen. My site is visited by me and 5 friends per day. So why is this happening?

Are there errors in my script? I do NOT use persistent connections.
Is it possible that a missing close of a connection can lead to this problem?
Or is it because I am on a shared host and also the Connection to the mysql db are shared?

Derezo
Member #1,666
April 2001
avatar

Make sure you're closing your connections when you're done with them. Otherwise you may be leaving a bunch of dead connections open.

Happened to me in a C# site I was working on. Of course, Microsoft doesn't give you a nice relevant error like that. ;)

[edit]

Quote:

Is it possible that a missing close of a connection can lead to this problem?
Or is it because I am on a shared host and also the Connection to the mysql db are shared?

Could be either.

"He who controls the stuffing controls the Universe"

count
Member #5,401
January 2005

Ok. Thanks. I thought I closed everything. This didn´t happen for quite a while.
But after this I will have to check all the scripts again.
But if they are ok and everything is closed properly I probably can´t do anything about this error, right?

[edit]
missed your edit. if it could be a problem of the shared host, I can´t do anything about it.

GullRaDriel
Member #3,861
September 2003
avatar

Quote:

I probably can´t do anything about this error, right?

"If you need to support more connections, you should restart mysqld with a larger value for this variable."

If you can't, you are right. You can't do anything else than asking your FAI to upgrade the number of connection, ask him if connection are also mutuals and my bad, I think it's all.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

count
Member #5,401
January 2005

The site has been down a few times today.
I guess all this is not related to my site but a server issue.

If I want to change hosts is it possible to keep my internetadress? The Hosting service registered it for me so I doubt that it is possible but that would be very uncool because I have to give up the adress when I decide to change hosts.

Matthew Leverton
Supreme Loser
January 1999
avatar

If it's in their name, there's nothing you can do but ask them politely. Keep in mind with webhosting, you get what you pay for. A few dollars per month usually means you are on an overloaded server or with a company that is run out of a 15 year old's basement.

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

or with a company that is run out of a 15 year old's basement.

Or the 15yr olds company is hosted in a crappy datacenter with a crappy version of Fedora installed.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

BAF
Member #2,981
December 2002
avatar

Hey, I'm 16 and its RedHat. :-/

Thomas Fjellstrom
Member #476
June 2000
avatar

Hey, you were 15, and RedHat is worse than fedora since RedHat is old and unmaintained :P

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

GullRaDriel
Member #3,861
September 2003
avatar

Debian or FreeBSD are my personals choices when it comes to good OS's speak.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

BAF
Member #2,981
December 2002
avatar

I'd prefer Gentoo or similar, but I don't have much of a choice (considering I use plesk, there are no good free alternative to plesk, so I'm locked to which distros Plesk supports through my ISP as my ISP must install it).

Go to: