public function testClose()
 {
     if (empty($_ENV['DISQUE_SERVERS'])) {
         $this->markTestSkipped('no disque servers configured');
     }
     try {
         $servers = explode(',', $_ENV['DISQUE_SERVERS']);
         $c = new DefaultStream($servers[0]);
         $c->connect();
     } catch (ConnectException $e) {
         $this->markTestSkipped($e->getMessage());
     }
     $this->assertTrue($c->isConnected());
     $c->close();
     $this->assertFalse($c->isConnected());
 }
示例#2
0
文件: Pool.php 项目: 0x20h/phloppy
 /**
  * Connect to a random node in the node list.
  *
  * @return DefaultStream Stream to a connected node.
  *
  * @throws ConnectException
  */
 public function connect()
 {
     $nodes = $this->nodeUrls;
     while (count($nodes)) {
         // pick random server
         $idx = rand(0, count($nodes) - 1);
         try {
             $stream = new DefaultStream($nodes[$idx], $this->log);
             $stream->connect();
             return $stream;
         } catch (ConnectException $e) {
             $this->log->warning($e->getMessage());
         }
         // remove the selected server from the list
         array_splice($nodes, $idx, 1);
     }
     throw new ConnectException('unable to connect to any of [' . implode(',', $this->nodeUrls) . ']');
 }