From e8f63aefc308eab964ab1678f915a3dbb502b56f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 29 Mar 2021 18:49:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rpc/Client.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Rpc/Client.php b/Rpc/Client.php index 42d8fc29..ddd4d545 100644 --- a/Rpc/Client.php +++ b/Rpc/Client.php @@ -63,16 +63,23 @@ class Client extends Component /** - * @throws ReflectionException + * @return Client * @throws ComponentException * @throws NotFindClassException + * @throws ReflectionException * @throws Exception */ public function clientRecover(): static { + $host = $this->config['host'] ?? '127.0.0.1'; + $port = $this->config['port'] ?? 0; + if ($port < 0) { + return $this; + } + /** @var Channel $channel */ $channel = Snowflake::app()->get('channel'); - $channel->push($this->client, CClient::class); + $channel->push($this->client, $host . $port . CClient::class); $this->client = null; return $this; } @@ -110,13 +117,23 @@ class Client extends Component /** * @return mixed + * @throws ComponentException + * @throws NotFindClassException + * @throws ReflectionException * @throws Exception */ public function getClient(): CClient { /** @var Channel $channel */ $channel = Snowflake::app()->get('channel'); - return $channel->pop(CClient::class, function () { + + $host = $this->config['host'] ?? '127.0.0.1'; + $port = $this->config['port'] ?? 0; + if ($port < 0) { + throw new Exception('Related service not have port(404)'); + } + + return $channel->pop($host . $port . CClient::class, function () { $client = new CClient($this->config['mode'] ?? SWOOLE_SOCK_TCP); $client->set([ 'timeout' => 0.5,