$locationIds)); // Lookup of priority - first index (0) will be closest location in chain // low value is higher priority $locationsAssoc = array_flip($locationIds); $servers = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { if ($row['fixedip'] === '') { $row['fixedip'] = Property::getServerIp(); $defPrio = 2000; } else { $defPrio = 1000; } $ip = $row['fixedip'] ? $row['fixedip'] : $row['clientip']; if ($defPrio === 1000 && is_null($row['locationid'])) { $serverLoc = Location::getFromIp($ip); if ($serverLoc !== false) { $row['locationid'] = $serverLoc; } } $old = isset($servers[$ip]) ? $servers[$ip] : $defPrio; if (is_null($row['locationid']) || !isset($locationsAssoc[$row['locationid']])) { $servers[$ip] = min($defPrio, $old) . '.' . mt_rand(); } else { $servers[$ip] = min($locationsAssoc[$row['locationid']], $old) . '.' . mt_rand(); } } asort($servers, SORT_NUMERIC | SORT_ASC); ConfigHolder::add('SLX_DNBD3_SERVERS', implode(' ', array_keys($servers))); ConfigHolder::add('SLX_VM_DNBD3', 'yes');