PHP Bulletin Board Home
News About Home
Features of phpBB Test drive phpBB Downloads Support for phpBB The phpBB Community Styles for customising phpBB 3rd party modifications to phpBB

Support Home | Knowledge Base Home | Submit Article | Search Articles | Browse Articles
 Using multiple database users with PHPBB 
Description: Work-around for hosts who limit the number of queries per hour
Author: espicom
Date: Mon Jan 09, 2006 5:20 pm
Type: HowTo
Keywords: max_questions
Category: Administrating
Quote:
SQL Error : 1226 User 'myusername' has exceeded the 'max_questions' resource (current value: 50000)


While I will never understand why some hosting companies think it is easier to set up multiple users for one database, instead of simply increasing the max_questions value for the original user, I offer the following as a potential work-around for the problem.

There are several ways to attempt to use multiple database usernames. None are 100% successful, because there is no way to guarantee that a particular database user has enough queries ("Questions") left for the current hour to complete generating a page. Each page requires 5 to 10 (or more, with MODs) queries to complete, and even asking how how many queries remain is counted against you.

The simplest method I have come up with to "spread the load" is as follows:

In config.php, replace the assignment of $dbuser and $dbpasswd with code such as this:

Code:
$dbuser_temp = date("i") % 3; // split hour into 3 overlapping sections
switch ($dbuser_temp)
{
   case 0:
      $dbuser='username1';
      $dbpasswd = 'password1';
      break;
   case 1:
      $dbuser='username2';
      $dbpasswd = 'password2';
      break;
   case 2:
      $dbuser='username3';
      $dbpasswd = 'password3';
      break;
}


If you have only two users, change the "3" in the first line to a 2. More users? Change it to the number of users you have, and add additional case statements... Remembering that the MOD operator ("%") will return numbers between zero and n-1, for any "n" users you want to insert. If you have 10 users to distribute the load amongst, you would need case statements for 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

It is also possible to divide the hour up into segments, instead of scattering the "slots" around the whole hour. This runs the danger of hitting the limit prior to the completion of the segment, and taking the board off-line until the next segment begins. This method shortens the potential gaps.

Username: Password:
News | Features | Demo | Downloads | Support | Community | Styles | Mods | Links | Merchandise | About | Home
 © Copyright 2002 The phpBB Group.