eee
This commit is contained in:
+15
-14
@@ -28,8 +28,9 @@ use Kiri\Server\Events\OnTaskerStart;
|
||||
use Kiri\Server\Events\OnAfterRequest;
|
||||
use Kiri\Di\Inject\Container;
|
||||
use Swoole\Timer;
|
||||
//use Database\Base\PDO;
|
||||
use PDO;
|
||||
use Database\Base\PDO;
|
||||
|
||||
//use PDO;
|
||||
|
||||
/**
|
||||
* Class Connection
|
||||
@@ -123,14 +124,14 @@ class Connection extends Component
|
||||
*/
|
||||
protected function checkClientHealth(Pool $pool): void
|
||||
{
|
||||
$pool->flush($this->cds, $this->pool['min'] ?? 1);
|
||||
$length = $pool->size($this->cds);
|
||||
$pool->flush('mysql.' . $this->cds, $this->pool['min'] ?? 1);
|
||||
$length = $pool->size('mysql.' . $this->cds);
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
try {
|
||||
if (($client = $this->validator($pool)) === false) {
|
||||
break;
|
||||
}
|
||||
$pool->push($this->cds, $client);
|
||||
$pool->push('mysql.' . $this->cds, $client);
|
||||
} catch (\Throwable $exception) {
|
||||
if (!str_contains($exception->getMessage(), 'Client timeout.')) {
|
||||
$this->logger->error(throwable($exception), [$this->cds]);
|
||||
@@ -148,7 +149,7 @@ class Connection extends Component
|
||||
protected function validator(Pool $pool): PDO|bool
|
||||
{
|
||||
/** @var $client PDO */
|
||||
if (($client = $pool->get($this->cds)) === false) {
|
||||
if (($client = $pool->get('mysql.' . $this->cds)) === false) {
|
||||
return false;
|
||||
}
|
||||
if ($client->query('select 1') === false) {
|
||||
@@ -178,7 +179,7 @@ class Connection extends Component
|
||||
*/
|
||||
protected function getNormalClientHealth(): PDO
|
||||
{
|
||||
$data = $this->pool()->get($this->cds, $this->waite_time);
|
||||
$data = $this->pool()->get('mysql.' . $this->cds, $this->waite_time);
|
||||
if ($data === false) {
|
||||
throw new Exception('Client Waite timeout.');
|
||||
}
|
||||
@@ -304,7 +305,7 @@ class Connection extends Component
|
||||
public function release(PDO $pdo): void
|
||||
{
|
||||
if (!$this->inTransaction()) {
|
||||
$this->pool()->push($this->cds, $pdo);
|
||||
$this->pool()->push('mysql.' . $this->cds, $pdo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,7 +317,7 @@ class Connection extends Component
|
||||
*/
|
||||
public function clear_connection(): void
|
||||
{
|
||||
$this->pool()->flush($this->cds, 0);
|
||||
$this->pool()->flush('mysql.' . $this->cds, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -328,7 +329,7 @@ class Connection extends Component
|
||||
if ($this->timerId > -1) {
|
||||
Timer::clear($this->timerId);
|
||||
}
|
||||
$this->pool()->close($this->cds);
|
||||
$this->pool()->close('mysql.' . $this->cds);
|
||||
}
|
||||
|
||||
|
||||
@@ -337,8 +338,8 @@ class Connection extends Component
|
||||
*/
|
||||
public function newConnect(): \PDO
|
||||
{
|
||||
// $pdo = new PDO($this->database, $this->cds, $this->username, $this->password, [
|
||||
$pdo = new \PDO('mysql:dbname=' . $this->database . ';host=' . $this->cds, $this->username, $this->password, [
|
||||
$pdo = new PDO($this->database, $this->cds, $this->username, $this->password, [
|
||||
// $pdo = new \PDO('mysql:dbname=' . $this->database . ';host=' . $this->cds, $this->username, $this->password, [
|
||||
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
\PDO::ATTR_ORACLE_NULLS => \PDO::NULL_NATURAL,
|
||||
@@ -359,8 +360,8 @@ class Connection extends Component
|
||||
*/
|
||||
protected function pool(): Pool
|
||||
{
|
||||
if (!$this->connections->hasChannel($this->cds)) {
|
||||
$this->connections->created($this->cds, $this->pool['max'] ?? 1, [$this, 'newConnect']);
|
||||
if (!$this->connections->hasChannel('mysql.' . $this->cds)) {
|
||||
$this->connections->created('mysql.' . $this->cds, $this->pool['max'] ?? 1, [$this, 'newConnect']);
|
||||
}
|
||||
return $this->connections;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user