示例#1
0
 /**
  */
 public function lock($key)
 {
     $hkey = $this->hkey($key) . self::LOCK_SUFFIX;
     $i = 0;
     while (!$this->_predis->setnx($hkey, 1)) {
         usleep(min(pow(2, $i++) * 10000, 100000));
     }
     $this->_predis->expire($hkey, self::LOCK_TIMEOUT);
     $this->_locks[$key] = true;
 }
示例#2
0
    die(track(array()));
    //The RFC says its OK to return whatever we want when the client stops downloading,
    //however, some clients will complain about the tracker not working, hence we return
    //an empty bencoded peer list
}
//Update information of this peer and get all the other peers downloading the same file.
$map = $info_hash . ':' . $peer_id;
$r->sadd('torrents', $info_hash);
$r->sadd($info_hash, $peer_id);
$pid_list = $r->smembers($info_hash);
if (isset($ip4)) {
    $r->hmset($map, 'ip4', $ip4, 'port', $port, 'seed', $is_seed);
} else {
    $r->hmset($map, 'ip6', $ip6, 'port', $port, 'seed', $is_seed);
}
$r->expire($map, __INTERVAL + __CLIENT_TIMEOUT);
$peers = array();
$i = $s = $l = 0;
foreach ($pid_list as $pid) {
    if ($pid == $peer_id) {
        continue;
    }
    $temp = $r->hmget($info_hash . ':' . $pid, 'ip4', 'ip6', 'port', 'seed');
    if (!$temp[0] && !$temp[1]) {
        //Remove the peer infomation if it's expired
        $r->srem($info_hash, $pid);
    } else {
        if ($temp[3]) {
            $s++;
        } else {
            $l++;
示例#3
0
文件: Client.php 项目: cargomedia/cm
 /**
  * @param string $key
  * @param int    $ttl
  */
 public function expire($key, $ttl)
 {
     $this->_redis->expire($key, $ttl);
 }
示例#4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // Start by printing some information about what the version
     $this->info('Running SeAT ' . \Config::get('seat.version') . ' Diagnostics');
     $this->line('');
     // It is important to run the command as the user that the workers are running as.
     // This way, the checks that ensure file permissions are right are executed
     // properly. If this is not the case, notify the user
     $this->comment('If you are not already doing so, it is recommended that you run this as the user the workers are running as.');
     $this->comment('Eg: `sudo -u apache php artisan seat:diagnose`.');
     $this->comment('This helps to check whether the permissions are correct.');
     $this->line('');
     // Go ahead and get the configuration information using
     // the \Config helper and print that
     $this->info('SeAT configuration:');
     if (\Config::get('app.debug')) {
         $this->comment('[warning] Debug Mode On: Yes. It is recommended that you set this to false in app/config/app.php');
     } else {
         $this->line('[ok] Debug Mode On: No');
     }
     $this->line('Url: ' . \Config::get('app.url'));
     $this->line('Failed API limit: ' . \Config::get('seat.ban_limit'));
     $this->line('Ban count time: ' . \Config::get('seat.ban_grace') . ' minutes');
     $this->line('');
     // Check that the log files are writable
     $this->info('Logging:');
     if (is_writable(storage_path() . '/logs/laravel.log')) {
         $this->line('[ok] ' . storage_path() . '/logs/laravel.log is writable.');
     } else {
         $this->error('[error] ' . storage_path() . '/logs/laravel.log is not writable.');
     }
     $this->line('');
     // Grab the database configurations from the config,
     // obviously hashing out the password
     $this->info('Database configuration:');
     $this->line('Database driver: ' . \Config::get('database.default'));
     $this->line('MySQL Host: ' . \Config::get('database.connections.mysql.host'));
     $this->line('MySQL Database: ' . \Config::get('database.connections.mysql.database'));
     $this->line('MySQL Username: '******'database.connections.mysql.username'));
     $this->line('MySQL Password: '******'*', strlen(\Config::get('database.connections.mysql.password'))));
     $this->line('');
     // Test the database connection. An exception will be
     // thrown if this fails, so we can catch it and
     // warn accordingly
     $this->info('Database connection test...');
     try {
         $this->line('[ok] Successfully connected to database `' . \DB::connection()->getDatabaseName() . '` (did not test schema)');
     } catch (\Exception $e) {
         $this->error('[error] Unable to obtain a MySQL connection. The error was: ' . $e->getCode() . ': ' . $e->getMessage());
     }
     $this->line('');
     // Get the Redis cache configuration and print it
     $this->info('Redis configuration:');
     $this->line('Redis Host: ' . \Config::get('database.redis.default.host'));
     $this->line('Redis Port: ' . \Config::get('database.redis.default.port'));
     $this->line('');
     // Test using the Redis cache. Failure should again
     // throw an exception, so catch this also and
     // warn accordingly.
     $this->info('Redis connection test...');
     // Create a random string as the key we will try
     // to read and write
     $key_test = str_random(40);
     try {
         // Make use of the underlying Predis library to
         // connect directly to the Redis cache
         $redis = new \Predis\Client(array('host' => \Config::get('database.redis.default.host'), 'port' => \Config::get('database.redis.default.port')));
         // Set a new key, and modify its expiry
         $redis->set($key_test, \Carbon\Carbon::now());
         $redis->expire($key_test, 10);
         $this->line('[ok] Successfully set the key: ' . $key_test . ' and set it to expire in 10 seconds');
         // Attempt to read the newly place key
         $value_test = $redis->get($key_test);
         $this->line('[ok] Successfully retreived key: ' . $key_test . ' which has value: ' . $value_test);
     } catch (\Exception $e) {
         $this->error('[error] Redis test failed. The last error was: ' . $e->getCode() . ': ' . $e->getMessage());
     }
     $this->line('');
     // Testing Pheal
     $this->info('EVE API call test with phealng...');
     // Bootstrap a new Pheal instance for use
     BaseApi::bootstrap();
     $pheal = new Pheal();
     // Test that Pheal usage is possible by calling the
     // ServerStatus() API
     try {
         $server_status = $pheal->serverScope->ServerStatus();
         $this->line('[ok] Testing the ServerStatus API call returned a response reporting ' . $server_status->onlinePlayers . ' online players, with the result cache expiring ' . \Carbon\Carbon::parse($server_status->cached_until)->diffForHumans());
     } catch (\Exception $e) {
         $this->error('[error] API Call test failed. The last error was: ' . $e->getCode() . ': ' . $e->getMessage());
     }
     $this->line('');
 }