Beispiel #1
0
function DBConnect($alternate = false)
{
    global $db;
    static $connected = false;
    if ($connected && !$alternate) {
        return $db;
    }
    $isCLI = PHP_SAPI == 'cli';
    $host = 'localhost';
    $user = $isCLI ? DATABASE_USERNAME_CLI : DATABASE_USERNAME_WEB;
    $pass = $isCLI ? DATABASE_PASSWORD_CLI : DATABASE_PASSWORD_WEB;
    $database = DATABASE_SCHEMA;
    $thisDb = new mysqli($host, $user, $pass, $database);
    if ($thisDb->connect_error) {
        if (!$isCLI) {
            if ($thisDb->connect_errno == 1226) {
                // max_user_connections
                APIMaintenance('+2 minutes', '+2 minutes');
                exit;
            }
        }
        $thisDb = false;
    } else {
        $thisDb->set_charset("utf8");
        $thisDb->query('SET time_zone=\'+0:00\'');
    }
    if (!$alternate) {
        $db = $thisDb;
        $connected = !!$db;
    }
    return $thisDb;
}
Beispiel #2
0
    $bonusLevelCache[$id] = $level;
}
$stmt->close();
$maxPacketSize = 0;
$stmt = $db->prepare('show variables like \'max_allowed_packet\'');
$stmt->execute();
$stmt->bind_result($nonsense, $maxPacketSize);
$stmt->fetch();
$stmt->close();
unset($nonsense);
$loopStart = time();
$toSleep = 0;
while (!$caughtKill && time() < $loopStart + 60 * 30) {
    heartbeat();
    sleep(min($toSleep, 10));
    if ($caughtKill || APIMaintenance()) {
        break;
    }
    ob_start();
    $toSleep = NextDataFile();
    ob_end_flush();
    if ($toSleep === false) {
        break;
    }
}
DebugMessage('Done! Started ' . TimeDiff($startTime));
function GetDBLock($db, $lockName)
{
    $now = microtime(true);
    $stmt = $db->prepare('select get_lock(?, 30)');
    $stmt->bind_param('s', $lockName);
Beispiel #3
0
<?php

chdir(__DIR__);
$startTime = time();
require_once '../incl/incl.php';
require_once '../incl/heartbeat.incl.php';
require_once '../incl/memcache.incl.php';
require_once '../incl/subscription.incl.php';
RunMeNTimes(1);
CatchKill();
if (!DBConnect()) {
    DebugMessage('Cannot connect to db!', E_USER_ERROR);
}
if (APIMaintenance()) {
    DebugMessage('API Maintenance in progress, not pruning history!', E_USER_NOTICE);
    exit;
}
CleanOldData();
DebugMessage('Done! Started ' . TimeDiff($startTime));
function CleanOldData()
{
    global $db, $caughtKill;
    if ($caughtKill) {
        return;
    }
    DebugMessage("Starting, getting houses");
    $house = null;
    $houses = [];
    $stmt = $db->prepare('SELECT DISTINCT house FROM tblRealm WHERE house is not null');
    $stmt->execute();
    $stmt->bind_result($house);
Beispiel #4
0
<?php

require_once __DIR__ . '/../incl/incl.php';
require_once __DIR__ . '/../incl/memcache.incl.php';
if (!isset($argv[1])) {
    DebugMessage('Manual API Maintenance called without time argument. Add expected completion timestamp to command line (or 0 to end maintenance)', E_USER_ERROR);
}
APIMaintenance($argv[1], isset($argv[2]) ? $argv[2] : false);
Beispiel #5
0
$tables = ['data' => ['tblBonusSet' => '1=1', 'tblHouseCheck' => '1=1', 'tblItemBonusesSeen' => '1=1', 'tblItemGlobal' => '1=1', 'tblItemHistoryDaily' => 'item in (select id from tblDBCItem where auctionable=1)', 'tblItemHistoryMonthly' => 'item in (select id from tblDBCItem where auctionable=1)', 'tblItemLevelsSeen' => '1=1', 'tblItemSummary' => '1=1', 'tblPet' => '1=1', 'tblPetSummary' => '1=1', 'tblRealm' => '1=1', 'tblSnapshot' => '1=1', 'tblWowToken' => '1=1'], 'user' => ['tblBitPayTransactions' => '1=1', 'tblEmailBlocked' => '1=1', 'tblEmailLog' => '1=1', 'tblPaypalTransactions' => '1=1', 'tblUser' => '1=1', 'tblUserAuth' => '1=1', 'tblUserMessages' => '1=1', 'tblUserRare' => '1=1', 'tblUserSession' => '1=1', 'tblUserWatch' => '1=1']];
$sqlFile = __DIR__ . '/../backup/backup' . $backupSet . '.' . date('Ymd') . '.sql.gz';
if (!(touch($sqlFile) && ($sqlFile = realpath($sqlFile)))) {
    DebugMessage("Could not create backup{$backupSet}.sql.gz", E_USER_ERROR);
    exit(1);
}
file_put_contents($sqlFile, '');
APIMaintenance($backupSet == 'data' ? '+45 minutes' : '+5 minutes');
$cmd = 'mysqldump --verbose --skip-opt --quick --allow-keywords --create-options --add-drop-table --add-locks --extended-insert --single-transaction --user='******' --password='******' --where=%s ' . escapeshellarg(DATABASE_SCHEMA) . " %s | gzip -c >> %s\n";
foreach ($tables[$backupSet] as $table => $where) {
    DebugMessage("Starting {$table}");
    if (($zp = gzopen($sqlFile, 'ab')) === false) {
        DebugMessage("Could not write table message for {$table} to {$sqlFile}");
    } else {
        gzwrite($zp, "select concat(now(), ' Inserting into {$table}');\n");
        gzclose($zp);
    }
    $trash = [];
    $ret = 0;
    exec(sprintf($cmd, escapeshellarg($where), escapeshellarg($table), escapeshellarg($sqlFile)), $trash, $ret);
    if ($ret != 0) {
        echo 'Error: ' . implode("\n", $trash);
        break;
    }
}
if ($backupSet == 'data') {
    APIMaintenance('+2 minutes', '+2 minutes');
} else {
    APIMaintenance(0);
}
DebugMessage('Done! Started ' . TimeDiff($startTime));
Beispiel #6
0
<?php

require_once 'memcache.incl.php';
require_once 'incl.php';
define('API_VERSION', 57);
define('THROTTLE_PERIOD', 3600);
// seconds
define('THROTTLE_MAXHITS', 200);
define('BANLIST_CACHEKEY', 'banlist_cidrs4');
define('BANLIST_FILENAME', __DIR__ . '/banlist.txt');
define('BANLIST_USE_DNSBL', false);
if (PHP_SAPI != 'cli' && ($inMaintenance = APIMaintenance()) !== false) {
    header('HTTP/1.1 503 Service Unavailable');
    header('Content-type: application/json');
    header('Cache-Control: no-cache');
    echo json_encode(['maintenance' => $inMaintenance]);
    exit;
}
function json_return($json)
{
    if ($json === false) {
        header('HTTP/1.1 400 Bad Request');
        exit;
    }
    ini_set('zlib.output_compression', 1);
    if (!is_string($json)) {
        $json = json_encode($json, JSON_NUMERIC_CHECK);
    }
    header('Content-type: application/json');
    echo $json;
    exit;