My web server run into such errors :
Server: example.com User: yyy MySQL Connection Limit: Current MySQL Connections: 81
I am investigating on the reasons of this problem.
The PHP manual says :
Thanks to the reference-counting system introduced with PHP 4's Zend Engine, a resource with no more references to it is detected automatically, and it is freed by the garbage collector. For this reason, it is rarely necessary to free the memory manually.
So, does keeping a reference to a MySQL identifier could be a problem for website with pages displayed in more than 3 seconds (generally) ?
I manage MySQL connections like that :
1 - I keep a global variable $LINK
as a reference to the MySQL resource
//MySQL connection
$LINK = 0;
function db_connect(){
//get variables
global $LINK,$CONF;
if($LINK == 0){
$LINK = @mysql_connect($CONF['host'], $CONF['user'], $CONF['password'])){
}
}
2 - I use a function like this one to do queries :
function db_query($sql){
global $LINK,$CONF,$NB_QUERIES,$TEMPS_QUERIES,$queries, $CLOSED;
if(db_connect()){
//do some debug stuff if needed
//execute the query
$result = @mysql_query($sql,$LINK);
//do some other debug stuff if needed
return $result;
} else {
return 0;
}
}
Am I looking in the right direction or there are some others things to look at first when having such errors?