Ejemplo n.º 1
0
 public static function config($rpcName)
 {
     $config = Yii::app()->params['Rpc_Service'];
     require_once ROOT_PATH . "/Lib/PHPClient/RpcClient.php";
     if (empty($config) || !isset($config[$rpcName]) || empty($config[$rpcName]['uri'])) {
         throw new exception('missing【' . $rpcName . '】config');
     }
     // 配置服务端列表
     RpcClient::config($config[$rpcName]['uri']);
 }
Ejemplo n.º 2
0
        {
            return json_encode($data) . "\n";
        }
        /**
         * 解析Rpc协议数据
         * @param string $bin_data
         * @return mixed
         */
        public static function decode($bin_data)
        {
            return json_decode(trim($bin_data), true);
        }
    }
}
// ==以下调用示例==
// 服务端列表
$address_array = array('tcp://127.0.0.1:2015');
// 配置服务端列表
RpcClient::config($address_array);
//$serverClient = RpcClient::instance('Zone');
//同步调用数据
//$result = $serverClient->getServerList();
//// ==异步调用==
//$serverClient->asend_getServerList();
//$result = $serverClient->arecv_getServerList();
//var_dump($result);
$onlineClient = RpcClient::instance('Online');
$result = $onlineClient->getOnline(1);
echo '<pre>';
print_r($result);
echo '</pre>';