Exemplo n.º 1
0
 /**
  * 通过读取 APF 的配置文件,获取 APS_Client 实例。返回的 Client 已经链接,可以直接使用。
  *
  * ```
  * config/aps.php
  * config['ip2city'] = array (
  *   'spID' = ...
  *   'spVer' = ...
  *   'endpoints' = array ('...')
  *   'linger' = ...
  *   'sndhwm' = ...
  *   'rcvhwm' = ...
  * );
  * ```
  *
  * @return APF_APS_Client12
  */
 public function get_client($configName)
 {
     $config = APF::get_instance()->get_config($configName, 'aps');
     if (empty($config)) {
         return null;
     }
     if (!isset($this->_clients[$configName])) {
         $spID = $config['spID'];
         $spVer = isset($config['spVer']) ? $config['spVer'] : null;
         $sender = defined('MACHINE_NAME') ? MACHINE_NAME : null;
         $linger = isset($config['linger']) ? $config['linger'] : 100;
         $sndhwm = isset($config['sndhwm']) ? $config['sndhwm'] : 1000;
         $rcvhwm = isset($config['rcvhwm']) ? $config['rcvhwm'] : 1000;
         $client = new APF_APS_Client12($spID, $spVer, $sender, $linger, $sndhwm, $rcvhwm);
         $endpoints = $config['endpoints'];
         foreach ($endpoints as $endpoint) {
             $client->connect($endpoint);
         }
         $this->_clients[$configName] = $client;
     }
     return $this->_clients[$configName];
 }