改名
This commit is contained in:
@@ -126,7 +126,6 @@ abstract class Pool extends Component
|
|||||||
{
|
{
|
||||||
$this->_items[$name]->push([time(), $client]);
|
$this->_items[$name]->push([time(), $client]);
|
||||||
unset($client);
|
unset($client);
|
||||||
$this->debug('release connect.' . $this->max . ':' . $this->size($name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -138,9 +137,20 @@ abstract class Pool extends Component
|
|||||||
if (!isset($this->_items[$name])) {
|
if (!isset($this->_items[$name])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while ([$time, $client] = $this->_items[$name]->pop(0.001)) {
|
$channel = $this->_items[$name];
|
||||||
|
while ([$time, $client] = $channel->pop(0.001)) {
|
||||||
unset($client);
|
unset($client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Channel[]
|
||||||
|
*/
|
||||||
|
protected function getChannels()
|
||||||
|
{
|
||||||
|
return $this->_items;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use PDO;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
use Snowflake\Abstracts\Pool;
|
use Snowflake\Abstracts\Pool;
|
||||||
|
use Swoole\Timer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Connection
|
* Class Connection
|
||||||
@@ -25,6 +26,48 @@ class Connection extends Pool
|
|||||||
|
|
||||||
private $creates = 0;
|
private $creates = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
if ($this->creates) {
|
||||||
|
Timer::clear($this->creates);
|
||||||
|
}
|
||||||
|
Timer::tick(30000, [$this, 'Heartbeat_detection']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public $lastTime = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $timer
|
||||||
|
*/
|
||||||
|
public function Heartbeat_detection($timer)
|
||||||
|
{
|
||||||
|
$this->creates = $timer;
|
||||||
|
if ($this->lastTime == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($this->lastTime + 600 < time()) {
|
||||||
|
$channels = $this->getChannels();
|
||||||
|
foreach ($channels as $name => $channel) {
|
||||||
|
while ($channel->length() > 0) {
|
||||||
|
$channel->pop();
|
||||||
|
$this->desc($name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ($this->lastTime + 500 < time()) {
|
||||||
|
$channels = $this->getChannels();
|
||||||
|
foreach ($channels as $name => $channel) {
|
||||||
|
while ($channel->length() > 5) {
|
||||||
|
$channel->pop();
|
||||||
|
$this->desc($name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $timeout
|
* @param $timeout
|
||||||
*/
|
*/
|
||||||
@@ -158,7 +201,6 @@ class Connection extends Pool
|
|||||||
if (Context::hasContext($coroutineName)) {
|
if (Context::hasContext($coroutineName)) {
|
||||||
return Context::getContext($coroutineName);
|
return Context::getContext($coroutineName);
|
||||||
}
|
}
|
||||||
// if ($this->size($coroutineName) < 1) {
|
|
||||||
if ($this->size($coroutineName) < 1 && $this->hasCreate[$coroutineName] < $this->max) {
|
if ($this->size($coroutineName) < 1 && $this->hasCreate[$coroutineName] < $this->max) {
|
||||||
return $this->saveClient($coroutineName, $this->nowClient($coroutineName, $config));
|
return $this->saveClient($coroutineName, $this->nowClient($coroutineName, $config));
|
||||||
}
|
}
|
||||||
@@ -216,6 +258,7 @@ class Connection extends Pool
|
|||||||
}
|
}
|
||||||
$this->push($coroutineName, $client);
|
$this->push($coroutineName, $client);
|
||||||
$this->remove($coroutineName);
|
$this->remove($coroutineName);
|
||||||
|
$this->lastTime = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user