diff --git a/Command.php b/Command.php index ccff23c..cbb8e52 100644 --- a/Command.php +++ b/Command.php @@ -109,6 +109,7 @@ class Command extends Component { $client = $this->connection->getConnection(); try { + $startTime = microtime(true); if (($prepare = $client->prepare($this->sql)) === false) { throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $client->errorInfo()[2]); } @@ -118,7 +119,7 @@ class Command extends Component $result = $method == 'rowCount' ? $prepare->rowCount() : $prepare->{$method}(PDO::FETCH_ASSOC); $prepare->closeCursor(); - $this->connection->println($this->sql, $this->params); + $this->connection->println($startTime, microtime(true), $this->sql, $this->params); return $result; } catch (Throwable $throwable) { @@ -151,6 +152,7 @@ class Command extends Component { $client = $this->connection->getConnection(); try { + $startTime = microtime(true); if (($prepare = $client->prepare($this->sql)) === false) { throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $prepare->errorInfo()[2]); } @@ -161,7 +163,7 @@ class Command extends Component $result = $client->lastInsertId(); - $this->connection->println($this->sql, $this->params); + $this->connection->println($startTime, microtime(true), $this->sql, $this->params); return $result == 0 ? $prepare->rowCount() : (int)$result; } catch (Throwable $throwable) { diff --git a/Connection.php b/Connection.php index 1a16cae..19508c3 100644 --- a/Connection.php +++ b/Connection.php @@ -79,14 +79,16 @@ class Connection extends Component /** + * @param float $startTime + * @param float $endTime * @param string $sql * @param array $params * @return void */ - public function println(string $sql, array $params = []): void + public function println(float $startTime, float $endTime, string $sql, array $params = []): void { if (is_callable($this->_println)) { - call_user_func($this->_println, $sql, $params); + call_user_func($this->_println, $startTime, $endTime, $sql, $params); } } @@ -113,7 +115,7 @@ class Connection extends Component */ public function tick(): void { - $this->timerId = Timer::tick($this->tick_time, fn() => $this->checkClientHealth($this->pool())); + $this->timerId = Timer::tick($this->tick_time, fn () => $this->checkClientHealth($this->pool())); } @@ -349,13 +351,13 @@ class Connection extends Component { $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, - \PDO::ATTR_STRINGIFY_FETCHES => false, - \PDO::ATTR_EMULATE_PREPARES => true, - \PDO::ATTR_TIMEOUT => $this->timeout, - \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset +\PDO::ATTR_CASE => \PDO::CASE_NATURAL, +\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, +\PDO::ATTR_ORACLE_NULLS => \PDO::NULL_NATURAL, +\PDO::ATTR_STRINGIFY_FETCHES => false, +\PDO::ATTR_EMULATE_PREPARES => true, +\PDO::ATTR_TIMEOUT => $this->timeout, +\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset ]); foreach ($this->attributes as $key => $attribute) { $pdo->setAttribute($key, $attribute);