Overcoming Hosting restrictions

If you run a large ecommerce store or bulletin board you may occasionally be plagued with the dreaded “userx has exceed the max_questions currently set at (some value)”. In my case my host limits the user mySQL queries per hour to 50000. Which sounds like a lot but when you consider an ecommerce store uses 10-100 queries per page load and the bots may be surfing the site at the same time as your visitors, it is very easy to reach the 50K mark. So here is my solution.

Before you begin reset your mySQL database password. This will clear the error message and release all sessions. If using IPowerWeb do: vdeck - preferences - Change password.

Step 1) In your mySQL database setup manager (not myPHPAdmin) add 2 more users (or more). Make sure they have the same password for your database as the original user. IF you do not have a database manager search the mySQL syntax for adding users. For IPowerWeb hosted sites use Vdeck - FileManager - Databases - Setup - Add Users. Test to make sure you can login to the database with them.

Step2) Find your configuration files that logs into the database or defines the user logins. IF using a PHP application it will most likely be in an includes directory. For OSCommerce it is in

  • Catalog/includes/config.php.

find the following line or something similar:

define (’DB_SERVER_USERNAME’, ‘your_database_name’);

Replace it with:

$db_users = array(’user_name_1′,’user_name_2′, ‘user_name_3′);
// insert your real usernames 1 2 &3
define(’DB_SERVER_USERNAME’,$db_user = $db_users[array_rand($db_users)]);

//comment replaced line if needed for future
// define(’DB_SERVER_USERNAME’,'your_database_name’);

This effectively selects a random user when the session begins and allows the database upto three times the normal queries. Be sure to test the individual user logins before modifying the config files. I hope this helps someone else out there.

UPDATED:
If the code above gives you mySQL errors try this

//Comment out this line
define('DB_SERVER_USERNAME','your_database_name');
//add:
$DB_SERVER_USERNAME_group[] = "xxxxxx1";
$DB_SERVER_USERNAME_group[] = "xxxxxx2";
$DB_SERVER_USERNAME_group[] = "xxxxxx3";
define('DB_SERVER_USERNAME', $DB_SERVER_USERNAME_group[ rand( 0, (sizeof($DB_SERVER_USERNAME_group)-1) ) ]);
//where xxxxxx# are your userids.

Comments are closed.