改名
This commit is contained in:
@@ -170,8 +170,9 @@ abstract class Pool extends Component
|
|||||||
}
|
}
|
||||||
$time = microtime(true);
|
$time = microtime(true);
|
||||||
if (!$this->hasItem($name)) {
|
if (!$this->hasItem($name)) {
|
||||||
$this->createByCallback($name, $callback);
|
return $this->createByCallback($name, $callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
$connection = $this->_items[$name]->pop(0.01);
|
$connection = $this->_items[$name]->pop(0.01);
|
||||||
if (microtime(true) - $time >= 0.007) {
|
if (microtime(true) - $time >= 0.007) {
|
||||||
$this->warning('Worker #' . env('worker') . ' get client use time ' . (microtime(true) - $time));
|
$this->warning('Worker #' . env('worker') . ' get client use time ' . (microtime(true) - $time));
|
||||||
@@ -187,14 +188,17 @@ abstract class Pool extends Component
|
|||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @param mixed $callback
|
* @param mixed $callback
|
||||||
|
* @return mixed
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function createByCallback($name, mixed $callback)
|
private function createByCallback($name, mixed $callback): mixed
|
||||||
{
|
{
|
||||||
if ($this->creates === -1 && !is_callable($callback)) {
|
if ($this->creates === -1 && !is_callable($callback)) {
|
||||||
$this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection']);
|
$this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->createClient($name, $callback);
|
||||||
|
|
||||||
if (!Context::hasContext('create::client::ing::' . $name)) {
|
if (!Context::hasContext('create::client::ing::' . $name)) {
|
||||||
$this->push($name, $this->createClient($name, $callback));
|
$this->push($name, $this->createClient($name, $callback));
|
||||||
Context::remove('create::client::ing::' . $name);
|
Context::remove('create::client::ing::' . $name);
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ class Connection extends Pool
|
|||||||
/**
|
/**
|
||||||
* @param $coroutineName
|
* @param $coroutineName
|
||||||
* @param $isMaster
|
* @param $isMaster
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function release($coroutineName, $isMaster)
|
public function release($coroutineName, $isMaster)
|
||||||
{
|
{
|
||||||
@@ -190,6 +191,8 @@ class Connection extends Pool
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->error('recover db client ' . $coroutineName);
|
||||||
|
|
||||||
/** @var PDO $client */
|
/** @var PDO $client */
|
||||||
$client = Context::getContext($coroutineName);
|
$client = Context::getContext($coroutineName);
|
||||||
if ($client->inTransaction()) {
|
if ($client->inTransaction()) {
|
||||||
@@ -241,7 +244,7 @@ class Connection extends Pool
|
|||||||
try {
|
try {
|
||||||
if (empty($client) || !($client instanceof PDO)) {
|
if (empty($client) || !($client instanceof PDO)) {
|
||||||
$result = false;
|
$result = false;
|
||||||
} else {
|
} else {
|
||||||
$result = true;
|
$result = true;
|
||||||
}
|
}
|
||||||
} catch (Error | Throwable $exception) {
|
} catch (Error | Throwable $exception) {
|
||||||
|
|||||||
Reference in New Issue
Block a user