This commit is contained in:
2023-08-29 22:20:30 +08:00
parent 91edb08238
commit c036cea809
+8 -12
View File
@@ -164,11 +164,10 @@ class Connection extends Component
*/ */
protected function validator(Pool $pool): PDO|bool protected function validator(Pool $pool): PDO|bool
{ {
if (($bool = $pool->get($this->cds)) === false) { /** @var $client PDO */
if (($client = $pool->get($this->cds)) === false) {
return false; return false;
} }
/** @var PDO $client */
[$client, $time] = $bool;
if ($client->query('select 1') === false) { if ($client->query('select 1') === false) {
throw new Exception($client->errorInfo()[1]); throw new Exception($client->errorInfo()[1]);
} }
@@ -218,7 +217,7 @@ class Connection extends Component
if ($data === false) { if ($data === false) {
throw new Exception('Client Waite timeout.'); throw new Exception('Client Waite timeout.');
} }
return $data[0]; return $data;
} }
@@ -287,8 +286,7 @@ class Connection extends Component
if ($pdo->inTransaction()) { if ($pdo->inTransaction()) {
$pdo->rollback(); $pdo->rollback();
} }
$this->pool()->push($this->cds, [$pdo, time()]); $this->release($pdo);
Context::remove($this->cds);
} }
} }
@@ -307,8 +305,7 @@ class Connection extends Component
if ($pdo->inTransaction()) { if ($pdo->inTransaction()) {
$pdo->commit(); $pdo->commit();
} }
$this->pool()->push($this->cds, [$pdo, time()]); $this->release($pdo);
Context::remove($this->cds);
} }
} }
@@ -327,8 +324,7 @@ class Connection extends Component
if ($this->inTransaction()) { if ($this->inTransaction()) {
$pdo->rollback(); $pdo->rollback();
} }
$this->pool()->push($this->cds, [$pdo, time()]); $this->release($pdo);
Context::remove($this->cds);
} }
@@ -349,10 +345,10 @@ class Connection extends Component
* 回收链接 * 回收链接
* @throws * @throws
*/ */
public function release(PDO $PDO): void public function release(PDO $pdo): void
{ {
if (!$this->inTransaction()) { if (!$this->inTransaction()) {
$this->pool()->push($this->cds, [$PDO, time()]); $this->pool()->push($this->cds, $pdo);
} }
} }