diff --git a/System/Abstracts/Pool.php b/System/Abstracts/Pool.php index 089c61ff..30ae1f75 100644 --- a/System/Abstracts/Pool.php +++ b/System/Abstracts/Pool.php @@ -207,62 +207,6 @@ abstract class Pool extends Component - protected int $lastTime = 0; - - - /** - * @param $timer - * @throws Exception - */ - public function Heartbeat_detection($timer) - { - $this->creates = $timer; - if ($this->lastTime == 0) { - return; - } - if ($this->lastTime + 60 < time()) { - $this->flush(0); - } else if ($this->lastTime + 30 < time()) { - $this->flush(2); - } - } - - - /** - * @param $retain_number - * @throws Exception - */ - protected function flush($retain_number) - { - $channels = $this->getChannels(); - foreach ($channels as $name => $channel) { - $this->pop($channel, $name, $retain_number); - } - if ($retain_number == 0) { - $this->debug('release Timer::tick'); - Timer::clear($this->creates); - $this->creates = 0; - } - } - - - /** - * @param $channel - * @param $name - * @param $retain_number - * @throws Exception - */ - protected function pop($channel, $name, $retain_number) - { - while ($channel->length() > $retain_number) { - [$timer, $connection] = $channel->pop(); - if ($connection) { - unset($connection); - } - $this->desc($name); - } - } - /** * @return Channel[] */ diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index f475322d..ebd722b0 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -18,6 +18,8 @@ use Swoole\Timer; class Connection extends Pool { + use Timeout; + public array $hasCreate = []; public int $timeout = 1900; @@ -25,8 +27,6 @@ class Connection extends Pool /** @var PDO[] */ protected array $connections = []; - public int $creates = 0; - /** * @param $timeout diff --git a/System/Pool/Redis.php b/System/Pool/Redis.php index d1b98e44..e589e6a8 100644 --- a/System/Pool/Redis.php +++ b/System/Pool/Redis.php @@ -20,11 +20,11 @@ use Swoole\Timer; class Redis extends Pool { + use Timeout; + private int $_create = 0; - public int $creates = 0; - /** * @param $value */ diff --git a/System/Pool/Timeout.php b/System/Pool/Timeout.php new file mode 100644 index 00000000..e2934acd --- /dev/null +++ b/System/Pool/Timeout.php @@ -0,0 +1,71 @@ +creates = $timer; + if ($this->lastTime == 0) { + return; + } + if ($this->lastTime + 60 < time()) { + $this->flush(0); + } else if ($this->lastTime + 30 < time()) { + $this->flush(2); + } + } + + + /** + * @param $retain_number + * @throws Exception + */ + protected function flush($retain_number) + { + $channels = $this->getChannels(); + foreach ($channels as $name => $channel) { + $this->pop($channel, $name, $retain_number); + } + if ($retain_number == 0) { + $this->debug('release Timer::tick'); + Timer::clear($this->creates); + $this->creates = 0; + } + } + + + /** + * @param $channel + * @param $name + * @param $retain_number + * @throws Exception + */ + protected function pop($channel, $name, $retain_number) + { + while ($channel->length() > $retain_number) { + [$timer, $connection] = $channel->pop(); + if ($connection) { + unset($connection); + } + $this->desc($name); + } + } +}