max_connections exceeded

max_connections exceeded

am 07.02.2007 11:25:21 von Phil Steer

I have just had a mySQL database added to my hosting account (NetNation) and
am experimenting with building an HTML page from the database using PHP.
However, although my test works (the page displays as expected), when I
request the test page multiple times I get the error:

Warning: mysql_connect(): User 'username' has exceeded the 'max_connections'
resource (current value: 10)

It then takes hours for the connections to timeout.

As far as I can see there is nothing wrong with my PHP code, which uses
mysql_close to explicitly close the connection opened with mysql_connect:

$db = mysql_connect( "hostname", "username", "password" ) ;
mysql_select_db( "database", $db ) ;
$sql = "SELECT * FROM articles" ;
$res = mysql_query( $sql, $db ) ;
echo "" ;
echo echoHead( mysql_result( $res, 0, "title" )) ;
echo "" ;
echoBorderTop() ;
showImage( mysql_result( $res, 0, "text" ), mysql_result( $res, 0,
"image" )) ;
echoBorderBottom() ;
echo "" ;
echo "" ;
mysql_close( $db ) ;
return ;
?>

(echoHead, echoBorderTop, showImage, and echoBorderBottom are simply
functions that I have written to help build the page - they make no calls to
database functions themselves)

Any suggestions as to the cause of the exceeded connections problem would be
much appreciated. Many thanks.

Re: max_connections exceeded

am 07.02.2007 13:02:04 von Shion

Phil Steer wrote:
> I have just had a mySQL database added to my hosting account (NetNation) and
> am experimenting with building an HTML page from the database using PHP.
> However, although my test works (the page displays as expected), when I
> request the test page multiple times I get the error:
>
> Warning: mysql_connect(): User 'username' has exceeded the 'max_connections'
> resource (current value: 10)
>
> It then takes hours for the connections to timeout.

There ain't anything wrong with your code,as I can see, it should work as
thought, would think the problem is at the server, I would suggest you try
with mysql_pconnect() and see if you can reuse connections and that way get
around troubles. http://www.php.net/manual/en/function.mysql-pconnect.php


--

//Aho

Re: max_connections exceeded

am 07.02.2007 22:39:14 von Phil Steer

Thanks for your reply and your confirmation that my code looks OK. Hopefully
my hosting service (NetNation) will come to the same conclusion and will
quickly resolve any problem with the server (although, since it is a shared
server, I can't see how anyone elses' mySQL database would work correctly).
Regarding the use of a persistent connection, I can see the logic (reuse an
exisitng connection rather than create a new one) but my worry is that I
might still end up exceeding the connection limit (even though that
shouldn't happen) but with connections that never time out, and so the
problem never clears. I think I'll wait for the moment and see what
NetNation come back with.

Best Regards, Phil

"J.O. Aho" wrote in message
news:52ttdsF1pnmmkU1@mid.individual.net...
> Phil Steer wrote:
>> Warning: mysql_connect(): User 'username' has exceeded the
>> 'max_connections'
>
> There ain't anything wrong with your code,as I can see, it should work as
> thought, would think the problem is at the server, I would suggest you try
> with mysql_pconnect() and see if you can reuse connections and that way
> get around troubles.
> http://www.php.net/manual/en/function.mysql-pconnect.php