|
-
Jun 14th, 2003, 07:11 AM
#1
Thread Starter
Fanatic Member
Warning: Too many connections.....
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
PHP Code:
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.
-
Jun 14th, 2003, 11:21 PM
#2
Stuck in the 80s
Code:
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.
-
Jun 15th, 2003, 07:42 AM
#3
Thread Starter
Fanatic Member
Yes, we are aware of this but it is a temp fix because it will still happen just not as often.
Thanks!
-
Jun 15th, 2003, 04:33 PM
#4
Stuck in the 80s
I've never heard of this happening before. What version are you running?
-
Jun 24th, 2003, 12:54 PM
#5
Frenzied Member
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
-
Jul 3rd, 2003, 09:23 PM
#6
Lively Member
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.
-
Sep 15th, 2003, 12:15 PM
#7
Thread Starter
Fanatic Member
mysql_close error
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?
PHP Code:
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
Last edited by lleemon; Sep 15th, 2003 at 12:55 PM.
-
Sep 15th, 2003, 01:07 PM
#8
Frenzied Member
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.
-
Sep 15th, 2003, 01:49 PM
#9
Thread Starter
Fanatic Member
Is there a difference between these in performance, etc...?
mysql_close(); vs mysql_close($connection);
-
Sep 15th, 2003, 02:02 PM
#10
Frenzied Member
I don't believe so, but why have a variable in it if you don't have to?
-
Sep 15th, 2003, 02:40 PM
#11
Stuck in the 80s
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?
-
Sep 15th, 2003, 04:21 PM
#12
<?="Moderator"?>
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?
-
Sep 15th, 2003, 09:53 PM
#13
Stuck in the 80s
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|