Jump to content

Recommended Posts

Posted

I'm getting some server errors on my site, and was wondering if anyone could point me at the right direction to get rid of them.

I only get them sometimes, and I haven't pinpointed yet what is causing them.

 

One is:

mysqli_connect(): (HY000/2002): Connection refused in [...]/openconnection.php on line 2

The code on line 2 of that file is

$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

Another is

(HY000/1203): User [...] already has more than 'max_user_connections' active connections in [...]/openconnection.php on line 2

 

Posted

This error is almost always poorly written code (or on rare occasion having way too much traffic).

 

You're opening too many MySQL connections at once. Best practice is to either open->query->close all together, or to open exactly one connection and reuse it for all queries your script will make. Also, always make sure to explicitly close connections with mysqli_close() when you're done with them. Don't just assume they'll close because the script died (though they should). Also, abandoning a handle to a connection (e.g. you let $dbc go out of scope or you unset() it...) doesn't close the connection, just leaves it open in limbo with no way to access it until something else causes it to close (typically PHP exiting).

 

Finally, worst case is you could move to Tommy since that server currently has no connection limit for MySQL, though that's subject to change if abused.

Guest
This topic is now closed to further replies.
×
×
  • Create New...