Example #1
0
        break;
        // Обновление ранее не найденных точек
    // Обновление ранее не найденных точек
    case 'recheck':
        require_once 'geoext.php';
        // TODO
        break;
        // Обслуживание таблиц в памяти
    // Обслуживание таблиц в памяти
    case 'memory':
        while (true) {
            if (!TRY_USE_MEMORY_TABLES) {
                logt('Memory tables are not used');
                continue;
            }
            $DataBaseStatus = GetStatsValue(STATS_DATABASE_STATUS);
            if ($DataBaseStatus == -1) {
                SetStatsValue(STATS_DATABASE_STATUS, DATABASE_PREPARE, true);
            }
            MemoryDataBaseInit();
            if ($DataBaseStatus != DATABASE_ACTIVE) {
                SetStatsValue(STATS_DATABASE_STATUS, DATABASE_ACTIVE, true);
            }
            sleep(10);
        }
        break;
    default:
        logt("Error: Unsupported action `{$argv['1']}'");
        break;
}
$db->close();
Example #2
0
function CheckRelevanceOfMemoryTables($UseFix)
{
    $Result = array('Base' => true, 'Geo' => true, 'BaseLastFixTime' => NULL, 'GeoLastFixTime' => NULL, 'BaseNeedFix' => false, 'GeoNeedFix' => false);
    $Stat = GetStatsValue(STATS_LAST_MEMORY_BASE_TABLE_SYNS);
    if ($Stat === FALSE || $Stat == -1) {
        if ($Stat == -1) {
            QuerySql('INSERT INTO STATS_TABLE SET StatId=' . STATS_LAST_MEMORY_BASE_TABLE_SYNS);
            $Stat = GetStatsValue(STATS_LAST_MEMORY_BASE_TABLE_SYNS);
            if ($Stat === FALSE || $Stat == -1) {
                $Result['Base'] = false;
            }
        } else {
            $Result['Base'] = false;
        }
    }
    $Result['BaseLastFixTime'] = $Stat !== FALSE && $Stat != -1 ? true : false;
    if ($Stat < time()) {
        // Recopy bases
        if ($UseFix) {
            QuerySql('TRUNCATE BASE_MEM_TABLE');
            $AffectedRows = -1;
            QuerySql('INSERT INTO BASE_MEM_TABLE SELECT * FROM BASE_TABLE_CONST ORDER BY time DESC', $AffectedRows);
            SetStatsValue(STATS_BASE_ROWN_NUMS, $AffectedRows, true);
            SetStatsValue(STATS_LAST_MEMORY_BASE_TABLE_SYNS, time() + MEMORY_TABLES_RELEVANCE_EXPIRES, true);
            $Result['BaseLastFixTime'] = time();
        } else {
            $Result['Base'] = false;
            $Result['BaseNeedFix'] = true;
        }
    }
    $Stat = GetStatsValue(STATS_LAST_MEMORY_GEO_TABLE_SYNS);
    if ($Stat === FALSE || $Stat == -1) {
        if ($Stat == -1) {
            QuerySql('INSERT INTO STATS_TABLE SET StatId=' . STATS_LAST_MEMORY_GEO_TABLE_SYNS);
            $Stat = GetStatsValue(STATS_LAST_MEMORY_GEO_TABLE_SYNS);
            if ($Stat === FALSE || $Stat == -1) {
                $Result['Geo'] = false;
            }
        } else {
            $Result['Geo'] = false;
        }
    }
    $Result['GeoLastFixTime'] = $Stat !== FALSE && $Stat != -1 ? true : false;
    if ($Stat < time()) {
        if ($UseFix) {
            QuerySql('TRUNCATE GEO_MEM_TABLE');
            $AffectedRows = -1;
            QuerySql('INSERT INTO GEO_MEM_TABLE SELECT * FROM GEO_TABLE_CONST', $AffectedRows);
            SetStatsValue(STATS_GEO_ROWN_NUMS, $AffectedRows, true);
            SetStatsValue(STATS_LAST_MEMORY_GEO_TABLE_SYNS, time() + MEMORY_TABLES_RELEVANCE_EXPIRES, true);
            $Result['GeoLastFixTime'] = time();
        } else {
            $Result['Geo'] = false;
            $Result['GeoNeedFix'] = true;
        }
    }
    return $Result;
}
Example #3
0
     break;
     // Общая статистика
 // Общая статистика
 case 'stat':
     set_time_limit(30);
     $json['result'] = true;
     date_default_timezone_set('UTC');
     $json['stat']['date'] = date('Y.m.d H:i:s');
     $mode = isset($_GET['mode']) ? (int) $_GET['mode'] : 0;
     if (!db_connect()) {
         $json['result'] = false;
         $json['error'] = 'database';
         break;
     }
     if ($mode == 0 || $mode == 1) {
         $json['stat']['total'] = GetStatsValue(STATS_BASE_ROWN_NUMS);
         if (1) {
             if ($res = QuerySql('SELECT COUNT(id) FROM BASE_TABLE')) {
                 $row = $res->fetch_row();
                 $json['stat']['total'] = (int) $row[0];
                 $res->close();
             }
         }
         if ($res = QuerySql('SELECT COUNT(BSSID) FROM GEO_TABLE WHERE (`quadkey` IS NOT NULL)')) {
             $row = $res->fetch_row();
             $json['stat']['onmap'] = (int) $row[0];
             $res->close();
         }
     }
     if ($mode == 0) {
         if ($res = QuerySql('SELECT COUNT(id) FROM BASE_TABLE WHERE NoBSSID = 0')) {