Jump to content

Too Many Connections To Database?


Usarjjaco

Recommended Posts

Hello Everyone,The problem I'm having is that every once in awhile on one of the sites I'm building I get an error on the front end that says something along the lines of "The user (my webhosting login name) has too many open connections to this database" ... I can of course refresh and move on, but I'm wondering if this is just because I'm logged in to the administrative end and checking things on the front end? I start all of my pages where I need the database with:

$con = mysql_connect("localhost","username","password");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("username_databasename", $con);

Perhaps It's because I start most of my pages with this connection? If this is the problem how would I go about fixing it? If it's just because I'm logged in on the back end and the front end then it's not problem at all... but if my users can see this error is there a way to get around it? From what I know (Which isn't a ton) The above code is basically what I have to use to connect to a database on seperate pages. ... I just don't want to get to the point where I have a hundred users and they are all getting this error message because they're accessing the database with the above data.Hope to hear from you guys soon!JJ

Link to comment
Share on other sites

You should probably contact your host about that... if two simultaneous connections are enough to produce such an error, then they're either opposing too much restriction on you for the sake of limiting you (and persuading you to pay more), or have limited it because they lack the hardware to keep up with it.

Link to comment
Share on other sites

You should probably contact your host about that... if two simultaneous connections are enough to produce such an error, then they're either opposing too much restriction on you for the sake of limiting you (and persuading you to pay more), or have limited it because they lack the hardware to keep up with it.
Ok, I was just making sure that there wasn't a way to make each individual user have his/her own connection to the DB. (because each person has their own member name/password / etc) . I'll contact my hosts support today and see what they say.EDIT: I use hostmonster with Cpanel... if anyone has any advice on the matter :)
Link to comment
Share on other sites

Ok, I was just making sure that there wasn't a way to make each individual user have his/her own connection to the DB. (because each person has their own member name/password / etc) . I'll contact my hosts support today and see what they say.EDIT: I use hostmonster with Cpanel... if anyone has any advice on the matter :)
15 Simultaneous connections is what I found out. So basically if more than 15 people load a page at once wham bam thank you mam. ... Anyone have any advice on how I could optimize this / keep it from occurring as often? My site already has about 80 users and growing.. so I see the chances of 15 + page loads at the same time happening much more often soon :)
Link to comment
Share on other sites

15 Simultaneous connections is what I found out.
15?? Wow. The default for mySQL is 100, and I usually raise the limit on my servers to 200 or 250. I'd look at moving to a less restrictive host.
Link to comment
Share on other sites

User persistent connections, as opposed to normal connections. To do that, you'll have to change your mysql_connect calls to mysql_pconnect() calls.When you open up a persistent connection, it should "persist" over many PHP invokations... but only if PHP is running as FCGI or Apache module. If it runs as CGI, it will be just as useless as mysql_connect(). You can find out if you're using an apache module with phpinfo(). Check out the "Server API" part, and if it says "CGI/FastCGI", then you're surely not using an apache module... whether it's CGI or FCGI... you'll have to ask your host, but don't hold your breath... few hosts use FCGI. If it's CGI (as it most likely would be the case), you'll have to ask that they do one of the following:1. Make PHP run as FastCGI or an Apache module.2. Increase your MySQL connections limit or abolish it altogether.3. Tell you how much would it cost for them to set you up with a separate server without any connection limits or which won't use CGI.4. Reccomend another host.

Link to comment
Share on other sites

User persistent connections, as opposed to normal connections. To do that, you'll have to change your mysql_connect calls to mysql_pconnect() calls.When you open up a persistent connection, it should "persist" over many PHP invokations... but only if PHP is running as FCGI or Apache module. If it runs as CGI, it will be just as useless as mysql_connect(). You can find out if you're using an apache module with phpinfo(). Check out the "Server API" part, and if it says "CGI/FastCGI", then you're surely not using an apache module... whether it's CGI or FCGI... you'll have to ask your host, but don't hold your breath... few hosts use FCGI. If it's CGI (as it most likely would be the case), you'll have to ask that they do one of the following:1. Make PHP run as FastCGI or an Apache module.2. Increase your MySQL connections limit or abolish it altogether.3. Tell you how much would it cost for them to set you up with a separate server without any connection limits or which won't use CGI.4. Reccomend another host.
Ok... now the limit is 15 connections per database.. is that still really low? I'll check on the FCGI. Anyone have any hosts they could recommend that provide a better bang for the buck? I mean I get by pretty cheaply right now for around $150-300 a year for the package I use.
Link to comment
Share on other sites

Ok... now the limit is 15 connections per database.. is that still really low? I'll check on the FCGI. Anyone have any hosts they could recommend that provide a better bang for the buck? I mean I get by pretty cheaply right now for around $150-300 a year for the package I use.
$300 yearly?!? If you pay ~$450 once, you can buy your own Windows Server 2008 (web edition) license! Many hosts charge that much money for dedicated servers (i.e. you having full control over everything, and not sharing it with other users).Personally, I haven't used any payed hosting packages (I have my own servers which get low traffic), so I can't actually recommend someone, but if it's dedicated hosting, by definition, anyone would do.
Link to comment
Share on other sites

$300 yearly?!? If you pay ~$450 once, you can buy your own Windows Server 2008 (web edition) license! Many hosts charge that much money for dedicated servers (i.e. you having full control over everything, and not sharing it with other users).Personally, I haven't used any payed hosting packages (I have my own servers which get low traffic), so I can't actually recommend someone, but if it's dedicated hosting, by definition, anyone would do.
I'll look to see how much it would be to get a dedicated server on there... how much did it cost you to set your personal server up? I suppose it might be a better option now that I'm growing.
Link to comment
Share on other sites

Like I said, my server is low on traffic, so my cheap solution may not be suitable for you... I mean I just don't have the traffic to stress test it.Also, my hardware is not specialized for a server, exactly in order to make it cheaper. In total, it costed me about $400. I have a special relationship with my ISP (we were their reseller), so they cover the electricity and internet bills. Because I'm low on traffic, I don't have to cover it myself - we share it. If I had to, it would probably cost me about $50 per month if not more. The price tag on the internet itself makes it that high - the required electricity costs about $15 per month where I live. If I had bought a specialized server hardware for higher traffic, the (one!) server would probably have costed me at least $700.Dedicated hosting providers usually store their servers in a special place (like the one my ISP stores my server at), where they share a high speed internet connection among the dedicated servers, which is why they can afford to give you a relatively cheaper offer than if you have your own internet connection.If you do persue having your own server AND internet connection, make sure you ask your ISP for high upload and lower download - in contrast to what average consumers need, as a server you need the very opposite - a high upload on your part means better download from your clients' perspective.

Link to comment
Share on other sites

Like I said, my server is low on traffic, so my cheap solution may not be suitable for you... I mean I just don't have the traffic to stress test it.Also, my hardware is not specialized for a server, exactly in order to make it cheaper. In total, it costed me about $400. I have a special relationship with my ISP (we were their reseller), so they cover the electricity and internet bills. Because I'm low on traffic, I don't have to cover it myself - we share it. If I had to, it would probably cost me about $50 per month if not more. The price tag on the internet itself makes it that high - the required electricity costs about $15 per month where I live. If I had bought a specialized server hardware, the server would probably have costed me at least $700.Dedicated hosting providers usually store their servers in a special place (like the one my ISP stores my server at), where they share a high speed internet connection among the dedicaed servers, which is why they can afford to give you a relatively cheaper offer than if you have your own internet connection.If you do persue having your own server AND internet connection, make sure you ask your ISP for high upload and lower download - in contrast to what average consumers need, as a server you need the very opposite - a high upload on your part means better download from your clients' perspective.
Ok thanks a lot for the advice. I'll start looking into things in that direction :)
Link to comment
Share on other sites

I'll look to see how much it would be to get a dedicated server on there... how much did it cost you to set your personal server up? I suppose it might be a better option now that I'm growing.
I rent several dedicated servers for ~$130 a month each. One box has about 100 domains on it and routinely serves about 5 million pages per month or so (about 1 million a month off of one particularly busy domain). Even with all that on it, it still usually runs at a pretty low load (.5 to .8). I don't remember all the specs, but they're all dual core, 4Gb memory, 160Gb disk, dual NICs, running Debian Lenny with ispCP control panel. It's probably not the best deal out there, but it works for me. 24/7 support and generous BW limits (which I appreciate, lol).
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...