Jump to content

Recommended Posts

I just launched a new site on bluehost and I have gotten the error:

mysql_connect()...Too many connections in...

 

Bluehost says the max connections is 30 and I don't have access to change that. All of my files close database connections at the end of the file.

 

That being said, I don't have many users yet and this problem worries me. Any insight/suggestions?

 

 

Link to comment
https://forums.phpfreaks.com/topic/137651-too-many-mysql-connections/
Share on other sites

Thats is the problem with the hosting sites, i also face this type of problems before.

May be there is no problem in your scripts. If you are using free hosting. then sometime they stop multiple connections for the sake of their servers. I think this should be the reason for you too.

do not use more than 1 connection? reuse the same connection, that way you will eliminate the error.. there is no reason to have more than 1 database.. maybe more than 1 table for 1 purpose, but more than 1 database for 1 purpose, is excessive, and pointless..

 

so.. using only 1 mysql connection = actually more effective also.

 

I used to open connections whenever I needed 1, instead of reusing already open ones..

 

also, this error isn't you opening and not closing.. because @ the very end of php, resources, variables, and any other created data is destroyed, unless you're in some older php version or something.

 

so mysql_close() was really intended for mid-execution resource disposal..

 

shorten your amount of mysql_connect() to a lower number of calls, if not to 1..

 

heres an idea:

 

just have a connect.php

 

and inside do your mysql_connect() whatever

 

then at the very top of each page, do

 

include("connect.php");

 

then every other include below it has access to the connection resource.. thus completely eliminating the need for more than 1 mysql_connect()

The issue you are having is common if your site recently generated a lot of traffic. Especially with free/cheap hosts it is even more seen cause they do not care to fix it unless you pay more. If you had a dedicated you can change the max number of MySQL connections easily and it fixes the problem.

 

I had this when my site started getting 10,000+ hits a day and had to change the max connections in MySQL and have not had that problem since.

 

Unfortunately without a dedicated server you will have to ask them to change it, and they probably will not.

 

 

Oh and the pconnect, I do not think would help, because it seems he has more than a few hundred users that connect at a time, which is what is causing the issue.

 

This is assuming you are really only opening one connection per page and no more. If you are opening more than 1 per each page, do as Russell said and re-design your script to use 1 database call per connection.

Oh and the pconnect, I do not think would help, because it seems he has more than a few hundred users that connect at a time, which is what is causing the issue.

 

Oh.

 

This is assuming you are really only opening one connection per page and no more. If you are opening more than 1 per each page, do as Russell said and re-design your script to use 1 database call per connection.

 

May I suggest creating a class that connects to MySQL and storing the class in $_SESSION? Then putting mysql_close in the the __destruct function?

Oh and the pconnect, I do not think would help, because it seems he has more than a few hundred users that connect at a time, which is what is causing the issue.

 

Oh.

 

This is assuming you are really only opening one connection per page and no more. If you are opening more than 1 per each page, do as Russell said and re-design your script to use 1 database call per connection.

 

May I suggest creating a class that connects to MySQL and storing the class in $_SESSION? Then putting mysql_close in the the __destruct function?

 

mysql_close is unnecessary as russell pointed out php closes connections when the script exits. As for the class in session, that is fine, but you still have to re-instantiate/connect to the DB each time a page is loaded.

also note, I've only EVER worked with VDS/DS and currently own 2 VDS hosting plans, 1 with jumpline (which i really wouldn't recommend expensive and SHIT) and 1 with WestHost I got it at the $10 a month deal, and imo its really worth it lol

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.