예제 #1
0
 public function testSend()
 {
     try {
         $connection = Connection::connect();
     } catch (\Net\Gearman\Exception $exception) {
         return $this->markTestSkipped('Skipped. You can try this test on your machine with gearman running.');
     }
     Connection::send($connection, 'echo_req', array('text' => 'foobar'));
     do {
         $ret = Connection::read($connection);
     } while (is_array($ret) && !count($ret));
     Connection::close($connection);
     $this->assertInternalType('array', $ret);
     $this->assertEquals('echo_res', $ret['function']);
     $this->assertEquals(17, $ret['type']);
     $this->assertInternalType('array', $ret['data']);
     $this->assertEquals('foobar', $ret['data']['text']);
 }
예제 #2
0
 private function connectToAllServers()
 {
     foreach ($this->getServers() as $server) {
         try {
             $connection = Connection::connect($server);
             Connection::send($connection, "set_client_id", array("client_id" => $this->id));
             $this->connection[$server] = $connection;
         } catch (\Exception $exception) {
             $this->retryConn[$server] = time();
         }
     }
     if (empty($this->connection)) {
         throw new Exception("Couldn't connect to any available servers");
     }
 }