改名
This commit is contained in:
+17
-22
@@ -82,34 +82,36 @@ class ClientsPool extends Component
|
|||||||
$min = Config::get('databases.pool.min', 1);
|
$min = Config::get('databases.pool.min', 1);
|
||||||
|
|
||||||
$num = [];
|
$num = [];
|
||||||
|
$total = 0;
|
||||||
foreach (static::$_connections as $key => $channel) {
|
foreach (static::$_connections as $key => $channel) {
|
||||||
if (!isset($num[$key])) {
|
if (!isset($num[$key])) {
|
||||||
$num[$key] = 0;
|
$num[$key] = 0;
|
||||||
}
|
}
|
||||||
|
if ($channel->length() > $min) {
|
||||||
|
$this->flush($channel, $min);
|
||||||
|
}
|
||||||
$num[$key] += $channel->length();
|
$num[$key] += $channel->length();
|
||||||
|
if (str_starts_with('Mysql:', $key)) {
|
||||||
|
$total += $channel->length();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var_dump($num);
|
if ($total < 1) {
|
||||||
|
Timer::clear($this->creates);
|
||||||
// $length = $this->getChannel($name)->length();
|
$this->creates = -1;
|
||||||
// if ($length > $min) {
|
}
|
||||||
// $this->flush($min);
|
$this->debug('use client ' . $total);
|
||||||
// }
|
|
||||||
// $this->debug("$name -> ($length:$min)");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param $channel
|
||||||
* @param $retain_number
|
* @param $retain_number
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function flush($retain_number)
|
public function flush($channel, $retain_number)
|
||||||
{
|
{
|
||||||
$channels = $this->getChannels();
|
$this->pop($channel, $retain_number);
|
||||||
foreach ($channels as $name => $channel) {
|
|
||||||
$names[] = $name;
|
|
||||||
$this->pop($channel, $name, $retain_number);
|
|
||||||
}
|
|
||||||
static::$_connections = [];
|
static::$_connections = [];
|
||||||
if ($retain_number == 0) {
|
if ($retain_number == 0) {
|
||||||
Timer::clear($this->creates);
|
Timer::clear($this->creates);
|
||||||
@@ -120,11 +122,10 @@ class ClientsPool extends Component
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Channel $channel
|
* @param Channel $channel
|
||||||
* @param $name
|
|
||||||
* @param $retain_number
|
* @param $retain_number
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function pop(Channel $channel, $name, $retain_number): void
|
protected function pop(Channel $channel, $retain_number): void
|
||||||
{
|
{
|
||||||
if (Coroutine::getCid() === -1) {
|
if (Coroutine::getCid() === -1) {
|
||||||
return;
|
return;
|
||||||
@@ -134,7 +135,6 @@ class ClientsPool extends Component
|
|||||||
if ($connection) {
|
if ($connection) {
|
||||||
unset($connection);
|
unset($connection);
|
||||||
}
|
}
|
||||||
$this->decrement($name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,12 +292,7 @@ class ClientsPool extends Component
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$channel = static::$_connections[$name];
|
$channel = static::$_connections[$name];
|
||||||
$this->pop($channel, $name, 0);
|
$this->pop($channel, 0);
|
||||||
if ($this->creates > -1) {
|
|
||||||
Timer::clear($this->creates);
|
|
||||||
}
|
|
||||||
$channel->close();
|
|
||||||
static::$_connections[$name] = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user