My host only allows 3 mysql connections. When there are a lot of connected users the mysql_connect throws an error and the user gets the temporary down screen. If he presses F5 it works again.
Why isn't there a loop in each database adapters that tries n times to connect and then throws an error at the end of the loop ?
For example I modified the __construct method of the mysql.php file (not tested):
Code: Select all
function __construct( $host='localhost', $user, $pass, $db='', $table_prefix='') {
// perform a number of fatality checks, then die gracefully
if (!function_exists( 'mysql_connect' )) {
$this->_errorNum = 1;
return;
}
$i = 0;
$connected = false;
// try 5 times when there is a connection attempt error (max. connections number can be reached for example)
while ($i < 5 && !$connected) {
if (phpversion() < '4.2.0') {
if (!($connected = $this->_resource = @mysql_connect( $host, $user, $pass ))) {
$this->_errorNum = 2;
}
} else {
if (!($connected = $this->_resource = @mysql_connect( $host, $user, $pass, true ))) { // true forces a new connection even if the same username and password
$this->_errorNum = 2;
}
}
if ($connected && $db != '' && !mysql_select_db( $db, $this->_resource )) {
$this->_errorNum = 3;
$connected = false;
}
if (!$connected) {
sleep(1);
}
$i++;
}
if (!$connected) {
return;
}
parent::__construct($host, $user, $pass, $db, $table_prefix);
}
Thomas