Example #1
0
 /**
  * @return PhpBuf_RPC_Socket_Interface
  */
 public function get()
 {
     $copy = (array) $this->context->getServers();
     shuffle($copy);
     $count = count($copy);
     $lastException = null;
     for ($i = 0; $i < $count; ++$i) {
         $server = $copy[$i];
         try {
             return $this->factory->create($server['host'], $server['port']);
         } catch (PhpBuf_RPC_Socket_Exception $e) {
             $lastException = $e;
             //
             // next server
             // TODO: failover
             //
         }
     }
     if (null != $lastException) {
         throw new PhpBuf_RPC_Socket_Exception($lastException->getMessage(), $lastException->getCode());
     }
 }
Example #2
0
<?php

require dirname(__FILE__) . '/PhpBuf/lib/PhpBuf.php';
require dirname(__FILE__) . '/proto/FullTextService.php';
$ctx = new PhpBuf_RPC_Context();
$ctx->addServer('localhost', 17001);
$service = new Temperance_FullTextService($ctx);
$setParam = new Temperance_FullText_Request_Add();
$setParam->key = 'hoge';
$setParam->str = '本日は晴天なり';
$setParam->value = 'http://www.google.com/search?q=晴天';
$setParam->parser = Temperance_FullText_Request_Parser::MECAB;
$service->add($setParam);
$setParam = new Temperance_FullText_Request_Add();
$setParam->key = 'hoge';
$setParam->str = '本日は雨です';
$setParam->value = 'http://www.google.com/search?q=雨';
$setParam->parser = Temperance_FullText_Request_Parser::MECAB;
$service->add($setParam);
$setParam = new Temperance_FullText_Request_Add();
$setParam->key = 'hoge';
$setParam->str = '本日は快晴かも';
$setParam->value = 'http://www.google.com/search?q=快晴';
$setParam->parser = Temperance_FullText_Request_Parser::MECAB;
$service->add($setParam);
$setParam = new Temperance_FullText_Request_Add();
$setParam->key = 'hoge';
$setParam->str = '昨日は曇りでした';
$setParam->value = 'http://www.google.com/search?q=曇';
$setParam->parser = Temperance_FullText_Request_Parser::MECAB;
$service->add($setParam);