0

I just uploaded my current project on a free PHP hosting website and when i and my friend visited the website i got from PDO (MySQL) the error SQLSTATE[08004] [1040] Too many connections.

I use a Singleton class to manage the PDO (so i create only 1 PDO instance to do the queries). I do not close the PDO (set the PDO = null) since i read that the PHP does it by itself at the end of script execution.

I checked the mysql max_connections and it is set to 150. Isn't it a little weird to show this message with only 2 visitors???

Are the max_connections being shared/affected from other websites hosted on the same server (I can't imagine any other cause)?

Any ideas what causes this...

2
Contributors
4
Replies
13
Views
4 Years
Discussion Span
Last Post by tacticalweb
1

If you don't close the connection, it will time out after 180 seconds by default (because PHP is basically stateless, a connection is never re-used). Then it is re-added to the connection pool. If you close the connection as you should, this does not happen, and there will be no dangling connections causing this error.

0

Ok. Lets say this happens. Each page (which has no AJAX) will generate 1 connection (since i use a Singleton class i mentioned in the previous post). I had 150 max_connections according to MySQL variables. After 5-6 pages (i just had uploaded the website and we were only 2 persons viewing it) i got the error. That doesn't make sense. It would be 20 (10 connections from me and 10 from the other person) connections the maximum and still i got the error!!!

Is the number of max_connection individual for each database or is it shared throught the other databases from from other websites hosted on the same server?

0

Thx a lot :)

Now i only have to check max_user_connections. Something tells me that they don't give a "good" number of connections per user

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.