示例#1
0
 /**
  * Instanciate Socket Client
  *
  * @return Thrift\Transport\TSocket
  */
 protected function createSocket()
 {
     $nbHosts = count($this->config['hosts']);
     if ($nbHosts == 1) {
         $host = current($this->config['hosts']);
         $socket = new TSocket($host['host'], $host['port']);
         if (!empty($host['recvTimeout'])) {
             $socket->setRecvTimeout($host['recvTimeout']);
         }
         if (!empty($host['sendTimeout'])) {
             $socket->setSendTimeout($host['sendTimeout']);
         }
     } else {
         $hosts = array();
         $ports = array();
         foreach ($this->config['hosts'] as $host) {
             $hosts[] = $host['host'];
             $ports[] = $host['port'];
         }
         $socket = new TSocketPool($hosts, $ports);
         if (!empty($host['recvTimeout'])) {
             $socket->setRecvTimeout($host['recvTimeout']);
         }
         if (!empty($host['sendTimeout'])) {
             $socket->setSendTimeout($host['sendTimeout']);
         }
     }
     return $socket;
 }
示例#2
0
文件: test.php 项目: lucmichalski/fae
require_once 'bootstrap.php';
use Thrift\Transport\TSocketPool;
use Thrift\Transport\TBufferedTransport;
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Exception\TTransportException;
use Thrift\Exception\TProtocolException;
use fun\rpc\FunServantClient;
use fun\rpc\Context;
use fun\rpc\TCacheMissed;
use fun\rpc\TMongoMissed;
use fun\rpc\TMemcacheData;
try {
    $sock = new TSocketPool(array('localhost'), array(9001));
    $sock->setDebug(0);
    $sock->setSendTimeout(4000);
    $sock->setRecvTimeout(4000);
    $sock->setNumRetries(1);
    $transport = new TBufferedTransport($sock, 1024, 1024);
    $protocol = new TBinaryProtocol($transport);
    // get our client
    $client = new FunServantClient($protocol);
    $transport->open();
    $ctx = new Context(array('reason' => "phptest", 'rid' => hexdec(uniqid())));
    // ping
    $return = $client->ping($ctx);
    echo "[Client] ping received: ", $return, "\n";
    // id.next
    echo "[Client] id_next received:", $client->id_next($ctx), "\n";
    echo "[Client] id_next received:", $client->id_next($ctx), "\n";
    echo "[Client] id_next_with_tag received:", $client->id_next_with_tag($ctx, 5), "\n";