Esempio n. 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;
 }
Esempio n. 2
0
}
if ($argc > 2) {
    $host = $argv[1];
}
foreach ($argv as $arg) {
    if (substr($arg, 0, 7) == '--port=') {
        $port = substr($arg, 7);
    } else {
        if (substr($arg, 0, 11) == '--transport=') {
            $MODE = substr($arg, 11);
        }
    }
}
$hosts = array('localhost');
$socket = new TSocket($host, $port);
$socket = new TSocketPool($hosts, $port);
$socket->setDebug(TRUE);
if ($MODE == 'inline') {
    $transport = $socket;
    $testClient = new \ThriftTest\ThriftTestClient($transport);
} else {
    if ($MODE == 'framed') {
        $framedSocket = new TFramedTransport($socket);
        $transport = $framedSocket;
        $protocol = new TBinaryProtocol($transport);
        $testClient = new \ThriftTest\ThriftTestClient($protocol);
    } else {
        $bufferedSocket = new TBufferedTransport($socket, 1024, 1024);
        $transport = $bufferedSocket;
        $protocol = new TBinaryProtocol($transport);
        $testClient = new \ThriftTest\ThriftTestClient($protocol);
Esempio n. 3
0
<?php

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";