PDA

Click to See Complete Forum and Search --> : Warning: Too many connections.....


lleemon
Jun 14th, 2003, 07:11 AM
I am developing a site using PHP with Dreamweaver MX and connecting to a MySQL db on a Red Hat (linux). After so many hits to my site I get funky errors like Warning: Too many connections in /home/virtual/siteXX/fst/var/www/html/Connections/domain_name.php on line X Too many connections.

Yes, I understand that each page that is loaded is starting a connection but at the end of each page Dreamweaver MX releases it by doing a

mysql_free_result($recordset);

for each recordset.

We had success with our code for a over 6 months but all of a sudden after a upgrade to the box we keep getting this and our fix is to stop and restart the MySQL server ever so often.

Do we have a setting we need to change? I thought PHP would handle the closing the connection automatically? If this is wrong then Dreamweaver MX has a flaw in its code.

Thanks for any advice anyone can provide on this issue.

The Hobo
Jun 14th, 2003, 11:21 PM
mysql_free_result($recordset);

Is redundant, especially if you do it at the end of the page, as PHP frees the result when the script finishes executing.

There is a variable you can change in MySQL called max_connections. The default is 100. I'm not sure what would be safe to raise it to.

lleemon
Jun 15th, 2003, 07:42 AM
Yes, we are aware of this but it is a temp fix because it will still happen just not as often.

Thanks!

The Hobo
Jun 15th, 2003, 04:33 PM
I've never heard of this happening before. What version are you running?

phpman
Jun 24th, 2003, 12:54 PM
releasing it only works if the connection gets a big query. what you want is mysql_close() as that closes the connections, hence that is your problem

ALundrigan
Jul 3rd, 2003, 09:23 PM
The error points to overloading your MySQL server. Too many people are trying to get data from the server at once. There are 3 main solutions

1) As 'The Hobo' alluded to, you can change the max_connections directive. If you set it to 0, then there will be no limit on the number of concurrent connections. If you can do this, and you have a reasonable server, then everything will work out.

2) I'm not too familliar with persistent connections (mysql_pconnect()). Maybe that will work?

3) Only open a MySQL connection when you absolutely need it. Don't open it at the beginning of every page and close it at the end....Open the connection, do your query, close the connection and then do the operations with the MySQL recordset that you need to. This also works well.

lleemon
Sep 15th, 2003, 12:15 PM
Still having my connection issues. phpman, in response to your mysql_close(), I tried this and get an error.

Is anyone familar with the following error message?

Warning: mysql_close(): xx is not a valid MySQL-Link resource in /dir/html/htmlpagename.php on line xxx

After the:
mysql_free_result($connection);
I put:
mysql_close($connection);
and I get the error above.

Any ideas why? Do I have something set up incorrectly?

--------------------------------
FIXED

Sorry, I guess I was closing the recordset not the connection. That does help :D

phpman
Sep 15th, 2003, 01:07 PM
all you have to do is

mysql_close();

and that is it, no variable or anything. unless of course you have more than 1 connection to different databases.

lleemon
Sep 15th, 2003, 01:49 PM
Is there a difference between these in performance, etc...?
mysql_close(); vs mysql_close($connection);

phpman
Sep 15th, 2003, 02:02 PM
I don't believe so, but why have a variable in it if you don't have to?

The Hobo
Sep 15th, 2003, 02:40 PM
Originally posted by phpman
I don't believe so, but why have a variable in it if you don't have to?

Readability. If somebody not very familiar with PHP was browsing through your code, that might help them figure out what is going on.

But if that's not the case...why bother?

john tindell
Sep 15th, 2003, 04:21 PM
if you dont include the variable then it will close the last open connection, which would be okay for a simple page, but if you are trying to make lots and lots of connections, for some reason, then i suppose its just to make things cleaner? or not? :p

The Hobo
Sep 15th, 2003, 09:53 PM
Originally posted by john tindell
if you dont include the variable

Being the nonsegratory and nonracist person that I am, I try to include my variables in the same activities as all the other language constructs. ;)


PS: I appologize if "segratory" is not a word. It just sounded cool.