DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • April 19, 2019, 07:38:58 AM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1]   Go Down
  Print  
Author Topic: handling exceeded max_questions error....  (Read 4264 times)
0 Members and 1 Guest are viewing this topic.
lonnyl
Guest
« on: February 19, 2006, 05:34:29 AM »

For those of you dealing with a host that has a questions limit..... here is how to deal...

Create a txt. file called currdb.txt in your game directory and give it read/write permissions (777 for linux/Unix).

in dbconnect.php
replace
Code:
$DB_USER=dbusername"; //Database Username

with
Code:
$currentdb = fopen("currdb.txt","r");
if (!($currentdb)){
srand((double)microtime()*1000000);
$userseed = rand(1,12);
}else{
flock($currentdb, 2);
$userseed = fread($currentdb, 4);
flock($currentdb, 3);
fclose($currentdb);
$currentdb = fopen("currdb.txt","w+");
settype($userseed, "integer");
$nextseed = $userseed + 1;
if ($nextseed > 12) $nextseed = 1;
flock($currentdb, 2);
fputs($currentdb, $nextseed."\n");
flock($currentdb, 3);
fclose($currentdb);
}
if ($userseed == 1){
$DB_USER="dbusername"; //Database Username1
}elseif ($userseed == 2){
$DB_USER="dbusername2"; //Database Username2
}elseif ($userseed == 3){
$DB_USER="dbusername3"; //Database Username2
}elseif ($userseed == 4){
$DB_USER="dbusername4"; //Database Username4
}elseif ($userseed == 5){
$DB_USER="dbusername5"; //Database Username5
}elseif ($userseed == 6){
$DB_USER="dbusername6"; //Database Username6
}elseif ($userseed == 7){
$DB_USER="dbusername7"; //Database Username7
}elseif ($userseed == 8){
$DB_USER="dbusername8"; //Database Username8
}elseif ($userseed == 9){
$DB_USER="dbusername9"; //Database Username9
}elseif ($userseed == 10){
$DB_USER="dbusername10"; //Database Username10
}elseif ($userseed == 11){
$DB_USER="dbusername11"; //Database Username11
}else{
$DB_USER="dbusername12"; //Database Username12
}

if you have a 50,000 question per hour limit on your database users this will effectively give you 600,000.
This scheme will incriment the dbuser in currdb.txt to evenly distribute the load amongst 12 database users (you can edit this to more or less users to suit your needs).  If for some reason you do not get the currdb.txt file created or do not get the permissions set right the script falls back to a randomizing scheme, which will do much the same thing with a less than even distribution of db user usage.

Hope this helps someone......
Logged
lonnyl
Guest
« Reply #1 on: February 19, 2006, 06:24:42 AM »

I should also note that this code assumes that you have set the same password for all of your database users... if not you will need to move the $DB_PASS variables to the function as well.
Logged
lonnyl
Guest
« Reply #2 on: February 27, 2006, 01:09:56 PM »

And just one step further......

it seems that the question count can still be a little unbalanced depending on what different users are doing (or like my server where the user count does not always reset for one of the users).  So to resolve this issue one needs to add a few lines to dbwrapper.php

after
Code:
require_once("lib/show_backtrace.php");

add
Code:
global $SCRIPT_NAME;
$currentpage=$SCRIPT_NAME;
//added to supress max_questions errors
if (strstr(db_error(LINK),"max_questions")) redirect($currentpage);

this will force a refresh when the error returned contains max_questions....
Logged
ShadowRaven
Mod God
*****
Offline Offline

Posts: 805


Silence is a virtue...


View Profile WWW
« Reply #3 on: February 27, 2006, 04:57:24 PM »

I had the same problem when I was with Powweb. they had a max query limit of 72k per Db user per hour. I changed my dbconnect file to this after I created 2 more db users in MySQL(there was also a limit of only 3 users per DB you could make) :

Code:
$DB_HOST = "hostname";
$db_user_array[] = "username1"; //enter 1st user name
$db_user_array[] = "username2"; //enter 2nd user name
$db_user_array[] = "username3"; //enter 3rd user name
$DB_USER = $db_user_array[ rand( 0, ( sizeof($db_user_array) -1 ) ) ];
$DB_PASS = "password";
$DB_NAME = "dbname";
$DB_PREFIX = "";

And it worked great.
Logged

lonnyl
Guest
« Reply #4 on: February 28, 2006, 04:52:25 AM »

Yes... I originally started with a randomize routine, however that was not an even enough distrobution for me.... hence the actual counting and cycling.... and then it seems the host was not always resetting one of the users on the hour.  That is where the dbwrapper edit was born from....
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Play LoGD on Dragonprime

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
99 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search