Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved timeout to affect all calls to the client.

Removed server array requirement from constructor.
  • Loading branch information...
commit 919f0f6a148bb712150eaabb3541a4e184799523 1 parent 3a399d8
@tenorviol authored
Showing with 8 additions and 4 deletions.
  1. +6 −3 src/Thrift/Client.php
  2. +2 −1  test/ClientTest.php
View
9 src/Thrift/Client.php
@@ -38,15 +38,16 @@ class Thrift_Client {
private $servers;
private $options;
+ private $socket;
private $client;
private static $default_options = array(
'timeout'=>1,
);
- public function __construct($client_class, array $servers) {
+ public function __construct($client_class, $servers) {
$this->client_class = $client_class;
- $this->servers = $servers;
+ $this->servers = (array)$servers;
$this->options = self::$default_options;
}
@@ -55,7 +56,6 @@ private function client() {
foreach ($this->servers as $server) {
list($host, $port) = explode(':', $server);
$socket = new TSocket($host, $port);
- $socket->setRecvTimeout($this->options['timeout']*1000);
$protocol = new TBinaryProtocol($socket);
$client = new $this->client_class($protocol);
try {
@@ -63,6 +63,7 @@ private function client() {
} catch (TException $e) {
continue;
}
+ $this->socket = $socket;
$this->client = $client;
break;
}
@@ -70,6 +71,7 @@ private function client() {
throw new Exception('Unable to connect');
}
}
+ $this->socket->setRecvTimeout($this->options['timeout']*1000);
return $this->client;
}
@@ -85,6 +87,7 @@ public function __set($name, $value) {
}
public function __call($name, $args) {
+ $client = $this->client();
return call_user_func_array(array($this->client(), $name), $args);
}
}
View
3  test/ClientTest.php
@@ -34,7 +34,7 @@
class Thrift_ClientTest extends PHPUnit_Framework_TestCase {
private function createClient($port) {
- return new Thrift_Client('SillyClient', array("localhost:$port"));
+ return new Thrift_Client('SillyClient', "localhost:$port");
}
private function openupServer($port) {
@@ -88,6 +88,7 @@ public function testFailoverConnection() {
}
$failover_client = new Thrift_Client('SillyClient', array("localhost:$dead_port", "localhost:$this->port"));
+
$result = $failover_client->rot13('foo');
$this->assertEquals(str_rot13('foo'), $result);
}

0 comments on commit 919f0f6

Please sign in to comment.
Something went wrong with that request. Please try again.