Example #1
0
 /**
  * 初始化,参数检查,URL绑定
  *
  * @throws Exception\RuntimeException
  */
 protected function init()
 {
     $this->_client = new Yar_Client($this->_entry);
     $this->_client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, 2000);
     $this->_client->SetOpt(YAR_OPT_TIMEOUT, 20000);
     $this->_client->SetOpt(YAR_OPT_PACKAGER, $this->_package);
 }
Example #2
0
 public function rpc($entrypoint, $service)
 {
     $id = "_rpc.{$entrypoint}.{$service}";
     if (!isset($this->container[$id])) {
         $config = $this->_config['rpc'];
         if (empty($config['entry_points'][$entrypoint])) {
             throw new \RuntimeException("RPC entry point: {$entrypoint} is not found.");
         }
         $url = "{$config['entry_points'][$entrypoint]}?service={$service}";
         $rpc = new \Yar_Client($url);
         $rpc->SetOpt(YAR_OPT_TIMEOUT, empty($config['timeout']) ? '5000' : $config['timeout']);
         $rpc->SetOpt(YAR_OPT_PACKAGER, empty($config['packager']) ? 'php' : $config['packager']);
         $rpc->SetOpt(YAR_OPT_CONNECT_TIMEOUT, empty($config['connect_timeout']) ? '2000' : $config['connect_timeout']);
         $this->container[$id] = $rpc;
     }
     return $this->container[$id];
 }
 /**
  * 初始化,参数检查,URL绑定
  *
  * @throws Exception\RuntimeException
  */
 protected function init()
 {
     // 判断远程调用列表,返回URL
     $names = array_keys($this->_allows);
     $urls = array_values($this->_allows);
     // 本地调用与远程调用,本地调用、远程调用验证Token(验证机制相同)todo 远程调用验证机制
     if (empty($this->_app) || ucfirst($this->_app) == APP_NAME) {
         $url = APP_URL . $this->_entry;
     } elseif (in_array(strtolower($this->_app), $names)) {
         $url = $urls[array_search(strtolower($this->_app), $names)] . $this->_entry;
         $this->_params['yarsource'] = APP_NAME;
     } else {
         throw new Exception\RuntimeException("Yar Client app is invalid");
     }
     $this->_params['token'] = $this->getToken();
     if (empty($this->_module) || empty($this->_controller) || empty($this->_action)) {
         throw new Exception\RuntimeException("Yar Client [Module/Controller/Action] is empty");
     }
     $this->_client = new Yar_Client($url);
     $this->_client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, 2000);
     $this->_client->SetOpt(YAR_OPT_TIMEOUT, 20000);
     $this->_client->SetOpt(YAR_OPT_PACKAGER, $this->_package);
 }
Example #4
0
<?php

/**
 * 本脚本用来测试子站接口测试
 * http://queue.ch.gongchang.com/?name=subsearch&opt=status&auth=gc895316
 */
$params = array('page' => 1, 'keywords' => '府绸', 'cateid' => 0, 'areaid' => 0, 'zzname' => 'fangzhi', 'subtype' => 4, 'cate1' => 1962, 'baseKey' => '府绸', 'isspider' => false);
$client = new Yar_Client("http://rpcapi.ch.gongchang.com/rpc/Zzsearch_Getsearchdata");
$client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, 1);
$result = $client->product($params);
$result = msgpack_unpack($result);
var_dump($result);
Example #5
0
 public function cls($do)
 {
     $client = new \Yar_Client(self::REQUEST_URL . $do);
     $client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, 1000);
     return $client;
 }