eee
This commit is contained in:
+7
-8
@@ -51,12 +51,14 @@ class Connection extends Component
|
|||||||
|
|
||||||
public string $database = '';
|
public string $database = '';
|
||||||
|
|
||||||
public int $connect_timeout = 30;
|
public int $timeout = 30;
|
||||||
|
|
||||||
|
|
||||||
public int $waite_time = 3;
|
public int $waite_time = 3;
|
||||||
|
|
||||||
public int $idle_time = 60;
|
public int $tick_time = 60;
|
||||||
|
|
||||||
|
public int $idle_count = 3;
|
||||||
|
|
||||||
public array $pool = ['max' => 10, 'min' => 1];
|
public array $pool = ['max' => 10, 'min' => 1];
|
||||||
|
|
||||||
@@ -72,9 +74,6 @@ class Connection extends Component
|
|||||||
public bool $enableCache = false;
|
public bool $enableCache = false;
|
||||||
|
|
||||||
|
|
||||||
private ?PDO $_pdo = null;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@@ -129,7 +128,7 @@ class Connection extends Component
|
|||||||
*/
|
*/
|
||||||
public function tick(): void
|
public function tick(): void
|
||||||
{
|
{
|
||||||
$this->timerId = Timer::tick(120000, fn() => $this->checkClientHealth($this->pool()));
|
$this->timerId = Timer::tick($this->tick_time, fn() => $this->checkClientHealth($this->pool()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -140,6 +139,7 @@ class Connection extends Component
|
|||||||
*/
|
*/
|
||||||
protected function checkClientHealth(Pool $pool): void
|
protected function checkClientHealth(Pool $pool): void
|
||||||
{
|
{
|
||||||
|
$pool->flush($this->cds, $this->pool['min'] ?? 1);
|
||||||
$length = $pool->size($this->cds);
|
$length = $pool->size($this->cds);
|
||||||
for ($i = 0; $i < $length; $i++) {
|
for ($i = 0; $i < $length; $i++) {
|
||||||
try {
|
try {
|
||||||
@@ -151,7 +151,6 @@ class Connection extends Component
|
|||||||
if (!str_contains($exception->getMessage(), 'Client timeout.')) {
|
if (!str_contains($exception->getMessage(), 'Client timeout.')) {
|
||||||
$this->logger->error(throwable($exception), [$this->cds]);
|
$this->logger->error(throwable($exception), [$this->cds]);
|
||||||
}
|
}
|
||||||
$pool->abandon($this->cds);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,7 +387,7 @@ class Connection extends Component
|
|||||||
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
|
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
|
||||||
PDO::ATTR_STRINGIFY_FETCHES => false,
|
PDO::ATTR_STRINGIFY_FETCHES => false,
|
||||||
PDO::ATTR_EMULATE_PREPARES => true,
|
PDO::ATTR_EMULATE_PREPARES => true,
|
||||||
PDO::ATTR_TIMEOUT => $this->connect_timeout,
|
PDO::ATTR_TIMEOUT => $this->timeout,
|
||||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
|
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ class DatabasesProviders extends Providers
|
|||||||
'password' => $database['password'],
|
'password' => $database['password'],
|
||||||
'tablePrefix' => $database['tablePrefix'],
|
'tablePrefix' => $database['tablePrefix'],
|
||||||
'database' => $database['database'],
|
'database' => $database['database'],
|
||||||
'connect_timeout' => $database['connect_timeout'] ?? 10,
|
'timeout' => $database['timeout'] ?? 10,
|
||||||
'idle_time' => $database['idle_time'] ?? 60,
|
'tick_time' => $database['tick_time'] ?? 60,
|
||||||
'waite_time' => $database['waite_time'] ?? 3,
|
'waite_time' => $database['waite_time'] ?? 3,
|
||||||
'pool' => $clientPool,
|
'pool' => $clientPool,
|
||||||
'attributes' => $database['attributes'] ?? [],
|
'attributes' => $database['attributes'] ?? [],
|
||||||
|
|||||||
Reference in New Issue
Block a user