'Max Connections' already in use
Posted: Thu Apr 21, 2005 5:36 am
Hello!
My first post in a code forum, be gentle.
I've written a bit of forum software, currently in use here and here.
When the sites began, it worked fine, really quick, simple to use etc, but now the sites have grown the forum is running really slow. The first link is the worst.
Every now and then we get HTTP 500 errors, but more oftern than not, we get 'Max Connections' limit already in use / Lost connection to MySQL server during query.
Now, I'm not sure I understand the problem. The way it says Connections makes me think that the sites are just too big, as we only connect once per page view? - Or is it the way I do the MySQL queries which is killing it?
We connect at the top of each PHP script with the following code:
and use this little function to do the queries:
and we call that with this sort of code.
Sorry if this is the worst post ever.
Any advice / suggestions?
My first post in a code forum, be gentle.
I've written a bit of forum software, currently in use here and here.
When the sites began, it worked fine, really quick, simple to use etc, but now the sites have grown the forum is running really slow. The first link is the worst.
Every now and then we get HTTP 500 errors, but more oftern than not, we get 'Max Connections' limit already in use / Lost connection to MySQL server during query.
Now, I'm not sure I understand the problem. The way it says Connections makes me think that the sites are just too big, as we only connect once per page view? - Or is it the way I do the MySQL queries which is killing it?
We connect at the top of each PHP script with the following code:
Code: Select all
$mysql["server"] = '127.0.0.1'; // Mysql Server (i.e. localhost)
$mysql["database"] = 'xx'; // Mysql database
$mysql["username"] = 'xx'; // Mysql username
$mysql["password"] = 'xx'; // Mysql password
// connect to MySQL
$conn = mysql_connect ($mysql["server"], $mysql["username"], $mysql["password"]);
mysql_select_db($mysql["database"],$conn);Code: Select all
function MyQ($sqlString)
{
echo('<!--Excecuting Query: '.$sqlString.'--><img src="reddot.gif" border="0">');
if($sqlString)
{
$result = mysql_query($sqlString)
or die('<b>MySQL Error</b><br>Function: mysqlQuery();<br>Error Description: '.mysql_error().'<br>Sql ran: '.$sqlString.'<br>');
return $result;
}
else
{
echo('mysqlQuery() called with no SQL defined');
exit;
}
}Code: Select all
$RS = MyQ("select * from table");
while($Row = mysql_fetch_array($RS))
{
...
}
unset($Row);
mysql_free_result($RS);Sorry if this is the worst post ever.
Any advice / suggestions?