This commit is contained in:
2023-08-16 00:39:55 +08:00
parent fdfe210fef
commit c8f7a7dcb2
2 changed files with 28 additions and 1 deletions
+5 -1
View File
@@ -64,7 +64,11 @@ class Pool implements PoolInterface
if (!isset($this->_connections[$name])) { if (!isset($this->_connections[$name])) {
throw new Exception('Channel is not exists.'); throw new Exception('Channel is not exists.');
} }
return $this->_connections[$name]; $channel = $this->_connections[$name];
if ($channel->isClose()) {
$channel->reconnect();
}
return $channel;
} }
+23
View File
@@ -37,6 +37,29 @@ class PoolItem
} }
/**
* @return bool
*/
public function isClose(): bool
{
if ($this->_items instanceof Channel) {
return $this->_items->errCode == SWOOLE_CHANNEL_CLOSED;
}
return false;
}
/**
* @return void
*/
public function reconnect(): void
{
if ($this->_items instanceof Channel && $this->_items->errCode == SWOOLE_CHANNEL_CLOSED) {
$this->_items = new Channel($this->maxCreated);
}
}
/** /**
* @param Channel|SplQueue $items * @param Channel|SplQueue $items
*/ */