改名
This commit is contained in:
@@ -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[]
|
* @return Channel[]
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ use Swoole\Timer;
|
|||||||
class Connection extends Pool
|
class Connection extends Pool
|
||||||
{
|
{
|
||||||
|
|
||||||
|
use Timeout;
|
||||||
|
|
||||||
public array $hasCreate = [];
|
public array $hasCreate = [];
|
||||||
|
|
||||||
public int $timeout = 1900;
|
public int $timeout = 1900;
|
||||||
@@ -25,8 +27,6 @@ class Connection extends Pool
|
|||||||
/** @var PDO[] */
|
/** @var PDO[] */
|
||||||
protected array $connections = [];
|
protected array $connections = [];
|
||||||
|
|
||||||
public int $creates = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $timeout
|
* @param $timeout
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ use Swoole\Timer;
|
|||||||
class Redis extends Pool
|
class Redis extends Pool
|
||||||
{
|
{
|
||||||
|
|
||||||
|
use Timeout;
|
||||||
|
|
||||||
|
|
||||||
private int $_create = 0;
|
private int $_create = 0;
|
||||||
|
|
||||||
public int $creates = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param $value
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Snowflake\Pool;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Swoole\Timer;
|
||||||
|
|
||||||
|
trait Timeout
|
||||||
|
{
|
||||||
|
|
||||||
|
private int $creates = 0;
|
||||||
|
|
||||||
|
|
||||||
|
private 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user