Example #1
0
// was 0.2, for 20% change required. 0 means tweet every change
define('BROTLI_PATH', __DIR__ . '/brotli/bin/bro');
if (!DBConnect()) {
    DebugMessage('Cannot connect to db!', E_USER_ERROR);
}
$resultCodes = [1 => 'Success', 2 => 'Disabled', 3 => 'Other Error', 4 => 'None For Sale', 5 => 'Too Many Tokens', 6 => 'No', 8 => 'Auctionable Token Owned', 9 => 'Trial Restricted'];
$timeZones = ['US' => 'America/New_York', 'EU' => 'Europe/Paris', 'CN' => 'Asia/Shanghai', 'TW' => 'Asia/Taipei', 'KR' => 'Asia/Seoul'];
$timeLeftCodes = ['Short' => 'less than 30 minutes', 'Medium' => '30 minutes to 2 hours', 'Long' => '2 to 12 hours', 'Very Long' => 'over 12 hours'];
$timeLeftNumbers = ['Short' => 1, 'Medium' => 2, 'Long' => 3, 'Very Long' => 4];
$regionNames = ['NA' => 'North American', 'EU' => 'European', 'CN' => 'Chinese', 'TW' => 'Taiwanese', 'KR' => 'Korean'];
$loopStart = time();
$loops = 0;
$gotData = [];
while (!$caughtKill && time() < $loopStart + 60) {
    heartbeat();
    if (!($region = NextDataFile())) {
        break;
    }
    if ($region !== true) {
        $gotData[] = $region;
    }
    if ($loops++ > 30) {
        break;
    }
}
$forceBuild = isset($argv[1]) && $argv[1] == 'build';
if ($gotData || $forceBuild) {
    BuildIncludes(array_keys($timeZones));
    SendTweets($forceBuild ? array_keys($timeZones) : array_unique($gotData));
    SendAndroidNotifications(array_unique($gotData));
    DebugMessage('Done! Started ' . TimeDiff($startTime));
Example #2
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);
    $stmt->execute();
    $lockSuccess = null;
    $stmt->bind_result($lockSuccess);
    if (!$stmt->fetch()) {