ZC-1.5.5e, PHP 5.6.32, Database patch level 1.5.5
I get this log error once daily(User already has more than 'max_user_connections)
I spoke with my Server Host, My max db user connections is set at 50 per User. My understanding is that it is based on a concurrent basis. So there would have to be >= 50 db connections within milliseconds.
I read the previous posts regarding 'Rotating db users' .
*********************************************************
Code:
// Enter your 4 database usernames here.
// If you have only two, then repeat them: first, second, first, second
$dbuser[] = 'username1';
$db_pwd[] = 'password1';
$dbuser[] = 'username2';
$db_pwd[] = 'password1';
$dbuser[] = 'username3';
$db_pwd[] = 'password1';
$dbuser[] = 'username4';
$db_pwd[] = 'password1';
// NO NEED TO DO ANYTHING IN THIS SECTION:
// calculate the current "minute"
$current_minute = date('i');
// calculate which "quarter of the hour" we're in
$db_user_active = (int)($current_minute/15);
define('DB_SERVER_USERNAME', $dbuser[$db_user_active]);
define('DB_SERVER_PASSWORD', $db_pwd[$db_user_active]);
//echo $db_user_active;
*************************************************************
Based on the above code it seems that this, 50 or greater simultaneous db connections log error, would still occur. since each different db user would still
be the designated user for 15 minutes. if the concurrency occurred at the second the switch to the next user the max could be increased to 100 theoretically.
After doing some searching on this, I came up with the following code :
************************************************************
Code:
$dbusers = array(
array('user' => 'mysql_username_1', 'password' => 'mysql_password_1') // First MySQL user/password combination
, array('user' => 'mysql_username_2', 'password' => 'mysql_password_2') // Second MySQL user/password combination
, array('user' => 'mysql_username_3', 'password' => 'mysql_password_3') // Third MySQL user/password combination
);
$mysql_user = $dbusers[rand(0, count($dbusers) - 1)];
$config['MasterServer']['username'] = $mysql_user['user'];
$config['MasterServer']['password'] = $mysql_user['password'];
****************************************************************
The No. of db users could be increased beyond 3
Everytime a page is opened, 1 of the defined username/password combinations will be choosen at random, and by this reducing the number of connections for each user.
My questions are:
1) Will this code work?
If it does work this could eliminate those max user connections.
Bookmarks