Esempio n. 1
0
 public static function setFreestServer()
 {
     $best = array('id' => 0, 'address' => null, 'private_key' => null, 'free_space' => 0);
     if (!StorageServer::isFreestServerLocked()) {
         $servers = StorageServer::all(array('conditions' => 'critical=0'));
         foreach ($servers as $serv) {
             $opts = array('http' => array('method' => 'GET', 'timeout' => 5));
             $context = stream_context_create($opts);
             $content = @file_get_contents($serv->address . 'index.php', null, $context);
             if ($content !== false) {
                 if ($content == 'CRITICAL_ALERT') {
                     $serv->critical = 1;
                     $serv->save();
                 } else {
                     if ($content > $best['free_space']) {
                         $best = array('id' => $serv->id, 'address' => $serv->address, 'private_key' => $serv->private_key, 'free_space' => $content);
                     }
                 }
             }
         }
     }
     return $best['id'];
 }
Esempio n. 2
0
<?php

if (!StorageServer::isFreestServerLocked()) {
    $serv = StorageServer::setFreestServer();
    file_put_contents(CACHE . 'server.json', json_encode(array('in_use' => 0, 'id' => $serv)));
}