Jump to content

Urgent


djp1988
 Share

Recommended Posts

My php is outputting this message: Warning: mysql_connect() [function.mysql-connect]: Too many connections in connect.php on line 15I can't connect to any of my databases through my site, or on phpmyadmin, nor on my Sequel Pro applicationHave I lost my database? How can I fix this ?

Link to comment
Share on other sites

Okay, it's gone away now, but jesus christ ! That was scary !What could have caused this to happen? How can I avoid it? Should I add mysql_close() at the end of all my php documents?Please let me know, I am so scared now, I am backing up my DB right away :sI've just checked my stats and there's been no increase in traffic

Edited by djp
Link to comment
Share on other sites

No, none...How can we define a connection per user? is it a connection per page being loaded or one connection per ip ?I'm on a shared hosting on GoDaddy, maybe the quota is one for everyone? although GoDaddy says:"We allow up to 200 simultaneous connections per MySQL user"http://help.godaddy.com/topic/67/article/215Both my databases are on the same ip,

Link to comment
Share on other sites

No, none...How can we define a connection per user? is it a connection per page being loaded or one connection per ip ?I'm on a shared hosting on GoDaddy, maybe the quota is one for everyone? although GoDaddy says:"We allow up to 200 simultaneous connections per MySQL user"http://help.godaddy.com/topic/67/article/215Both my databases are on the same ip,
When you don't use mysql_close(), you're essentially using persistant connections - the connections is reused over multiple requests. This is good in reducing connection numbers. Yet, persistent connections may not always be reused (e.g. if the server is really busy), and could be left opened for some time, thereby increating connection numbers instead of reducing them.If you use mysql_close(), you'll decrease the performance of your app a little, since PHP will have to reestabilish the connection at each request. You'll be sure to decrease the connection numbers though, so this error will become less likely to appear. Note that it is impossible to completely get rid of it. If your server is visited by more than 200 people per second, you'll still see it. Edited by boen_robot
Link to comment
Share on other sites

I am realizing that I am including more then one times my mysql_connect php script, will this open multiple connections for the same script, or will the variables be overwritten and the previous connection aborted?I am trying to clean up my php script, but I am including my database connection in my header php and sometimes I need the connection where there's no header...so could this be bumping up the number of connections ?

Link to comment
Share on other sites

I am realizing that I am including more then one times my mysql_connect php script, will this open multiple connections for the same script, or will the variables be overwritten and the previous connection aborted?I am trying to clean up my php script, but I am including my database connection in my header php and sometimes I need the connection where there's no header...so could this be bumping up the number of connections ?
Could be... use include_once instead of include to avoid including the same file twice, while still keeping your code "fool proof".
Link to comment
Share on other sites

I am doing a require_once, so if I understand from your reply, if I require_once the same file twice, it'll ignore the second request?
Yes. If the file is already included, it won't include it again.
Link to comment
Share on other sites

It will only use persistent connections if you use mysql_pconnect to connect. Not using mysql_close will not create a persistent connection, it will automatically close the connection after the script ends when it deallocates all of the resources that the script was using. Unless the connection was opened as persistent. And yes, if you use mysql_connect more than once then you will open more than one connection.

Link to comment
Share on other sites

It will only use persistent connections if you use mysql_pconnect to connect. Not using mysql_close will not create a persistent connection, it will automatically close the connection after the script ends when it deallocates all of the resources that the script was using. Unless the connection was opened as persistent. And yes, if you use mysql_connect more than once then you will open more than one connection.
I saw pconnect yesterday (long after I posted that last reply...) and wondered myself about that. It explains a lot really. It appears djp's problem was indeed include_once, and I've been doing and thinking about things incorrectly for some time... it's times like these I'm glad I'm around :).
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...