modify plugin name
This commit is contained in:
+24
-37
@@ -28,8 +28,6 @@ class PDO implements StopHeartbeatCheck
|
||||
|
||||
private int $_timer = -1;
|
||||
|
||||
private int $_last = 0;
|
||||
|
||||
public string $dbname;
|
||||
public string $cds;
|
||||
public string $username;
|
||||
@@ -60,10 +58,10 @@ class PDO implements StopHeartbeatCheck
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->heartbeat_check();
|
||||
$eventProvider = Kiri::getDi()->get(EventProvider::class);
|
||||
$eventProvider->on(OnWorkerExit::class, [$this, 'onWorkerExit']);
|
||||
}
|
||||
@@ -82,50 +80,18 @@ class PDO implements StopHeartbeatCheck
|
||||
* @param Kiri\Server\Events\OnWorkerExit $exit
|
||||
* @return void
|
||||
*/
|
||||
public function onWorkerExit(OnWorkerExit $exit)
|
||||
public function onWorkerExit(OnWorkerExit $exit): void
|
||||
{
|
||||
$this->stopHeartbeatCheck();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function heartbeat_check(): void
|
||||
{
|
||||
if ($this->_timer === -1) {
|
||||
$this->_timer = Timer::tick(1000, [$this, 'waite']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function waite(): void
|
||||
{
|
||||
try {
|
||||
$tick = (int)Config::get('databases.pool.tick', 60);
|
||||
if ($this->_timer == -1 || time() - $this->_last > $tick) {
|
||||
$this->stopHeartbeatCheck();
|
||||
|
||||
$this->pdo = null;
|
||||
}
|
||||
} catch (\Throwable $throwable) {
|
||||
error($throwable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function stopHeartbeatCheck(): void
|
||||
{
|
||||
if ($this->_timer > -1) {
|
||||
Timer::clear($this->_timer);
|
||||
}
|
||||
$this->_timer = -1;
|
||||
$this->pdo = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -254,6 +220,27 @@ class PDO implements StopHeartbeatCheck
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function check(): bool
|
||||
{
|
||||
try {
|
||||
if (!($this->pdo instanceof \PDO)) {
|
||||
return $result = false;
|
||||
}
|
||||
$this->pdo->getAttribute(\PDO::ATTR_SERVER_INFO);
|
||||
|
||||
$result = true;
|
||||
} catch (\Throwable $throwable) {
|
||||
$this->pdo = null;
|
||||
$result = false;
|
||||
} finally {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PDOStatement $statement
|
||||
* @param array $params
|
||||
|
||||
Reference in New Issue
Block a user