This commit is contained in:
2021-09-07 14:52:24 +08:00
parent c0e8e317ac
commit d618ac4556
+19 -18
View File
@@ -73,14 +73,14 @@ class PDO implements StopHeartbeatCheck
*/ */
public function heartbeat_check(): void public function heartbeat_check(): void
{ {
if (env('state','start') == 'exit') { if (env('state', 'start') == 'exit') {
return; return;
} }
if ($this->_timer === -1 && Context::inCoroutine()) { if ($this->_timer === -1 && Context::inCoroutine()) {
$this->_timer = Timer::tick(1000, function () { $this->_timer = Timer::tick(1000, function () {
try { try {
if (env('state','start') == 'exit') { if (env('state', 'start') == 'exit') {
Kiri::getDi()->get(Logger::class)->critical('timer end'); Kiri::getDi()->get(Logger::class)->critical('timer end');
$this->stopHeartbeatCheck(); $this->stopHeartbeatCheck();
} }
if (time() - $this->_last > 10 * 60) { if (time() - $this->_last > 10 * 60) {
@@ -153,9 +153,9 @@ class PDO implements StopHeartbeatCheck
{ {
$pdo = $this->queryPrev($sql, $params); $pdo = $this->queryPrev($sql, $params);
defer(fn() => $pdo->closeCursor()); $result = $pdo->fetchAll(\PDO::FETCH_ASSOC);
$pdo->closeCursor();
return $pdo->fetchAll(\PDO::FETCH_ASSOC); return $result;
} }
@@ -169,9 +169,9 @@ class PDO implements StopHeartbeatCheck
{ {
$pdo = $this->queryPrev($sql, $params); $pdo = $this->queryPrev($sql, $params);
defer(fn() => $pdo->closeCursor()); $result = $pdo->fetch(\PDO::FETCH_ASSOC);
$pdo->closeCursor();
return $pdo->fetch(\PDO::FETCH_ASSOC); return $result;
} }
@@ -185,9 +185,9 @@ class PDO implements StopHeartbeatCheck
{ {
$pdo = $this->queryPrev($sql, $params); $pdo = $this->queryPrev($sql, $params);
defer(fn() => $pdo->closeCursor()); $result = $pdo->fetchColumn(\PDO::FETCH_ASSOC);
$pdo->closeCursor();
return $pdo->fetchColumn(\PDO::FETCH_ASSOC); return $result;
} }
@@ -201,9 +201,9 @@ class PDO implements StopHeartbeatCheck
{ {
$pdo = $this->queryPrev($sql, $params); $pdo = $this->queryPrev($sql, $params);
defer(fn() => $pdo->closeCursor()); $result = $pdo->rowCount();
$pdo->closeCursor();
return $pdo->rowCount(); return $result;
} }
@@ -251,14 +251,15 @@ class PDO implements StopHeartbeatCheck
if (!(($prepare = $this->_pdo()->prepare($sql)) instanceof PDOStatement)) { if (!(($prepare = $this->_pdo()->prepare($sql)) instanceof PDOStatement)) {
throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE); throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE);
} }
defer(fn() => $prepare->closeCursor());
if ($prepare->execute($params) === false) { if ($prepare->execute($params) === false) {
throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE); throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE);
} }
$result = 1;
if ($isInsert) { if ($isInsert) {
return (int)$this->_pdo()->lastInsertId(); $result = (int)$this->_pdo()->lastInsertId();
} }
return 1; $prepare->closeCursor();
return $result;
} }