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];
 }
Exemplo n.º 2
0
 public function aps_wait_for_replies($refs = null, $timeout = null)
 {
     $return = array();
     $replys = APF_APS_Client12::wait_for_replies($refs, $timeout);
     foreach ($replys as $key => $reply) {
         if ($reply->status == 200) {
             $return[$key] = $reply->result;
         }
     }
     return $return;
 }
Exemplo n.º 3
0
 public static function abandon_requests($refs = null)
 {
     if ($refs === null) {
         self::$pending_requests = array();
         self::$pending_replies = array();
         self::$pending_callbacks = array();
         return;
     }
     if (!is_array($refs)) {
         $refs = array($refs);
     }
     foreach ($refs as $ref) {
         unset(self::$pending_requests[$ref]);
         unset(self::$pending_callbacks[$ref]);
         unset(self::$pending_replies[$ref]);
     }
 }