/** * @brief 注册并行的client * @param \Aha\Network\Client $client * @return \Aha\Multi\Multi */ public function register(\Aha\Network\Client $client) { $client->setCallback(array($this, 'wait')); if (null === $client->getRequestId()) { $client->setRequestId(count($this->_arrClients)); } array_push($this->_arrClients, $client); return $this; }
/** * @brief 实例化redis client * @param type $conf * @return \Aha\Storage\Memory\Rediscli */ public function __construct($conf) { $host = $conf['host']; $port = $conf['port']; $timeout = $conf['timeout']; //TODO |SWOOLE_KEEP $client = new \swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC); parent::__construct($client, $host, $port, $timeout); $this->_initConfig(); return $this; }
/** * @brief 对外请求开始loop */ public function loop() { if ($this->_objClient->sock && $this->_objClient->isConnected()) { $this->_send($this->_objClient); //连接池取出的连接 send失败就关闭了吧 } else { $this->_objClient->connect($this->_host, $this->_port, $this->_connectTimeout); } return parent::loop(); }
/** * @brief 对外请求开始loop */ public function loop($callback = null) { if (null !== $callback) { $this->setCallback($callback); } $this->_buildRequest(); if ($this->_objClient->sock && $this->_objClient->isConnected()) { $this->_send($this->_objClient); //连接池取出的连接 send失败就关闭了吧 return parent::loop(); } if (null !== $this->_ip) { $this->_objClient->connect($this->_ip, $this->_port, $this->_connectTimeout); return parent::loop(); } //异步查找ip swoole_async_dns_lookup($this->_host, function ($host, $ip) { $this->_ip = $ip; $this->_objClient->connect($this->_ip, $this->_port, $this->_connectTimeout); return parent::loop(); }); }
/** * @brief 对外请求开始loop */ public function loop($callback = null) { if (null !== $callback) { $this->setCallback($callback); } if ($this->_objClient->sock && $this->_objClient->isConnected()) { $this->_send($this->_objClient); //连接池取出的连接 send失败就关闭了吧 } else { $this->_objClient->connect($this->_host, $this->_port, $this->_connectTimeout); } return parent::loop(); }