Skip to content

Commit

Permalink
change reconect wrapper to only check connection after inactivity
Browse files Browse the repository at this point in the history
instead of always checking every minute, only check the connection after a minute of inactivity.
this should better reflect how idle timeouts of sql servers work and remove most of the cases where this check was previously done.

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Feb 9, 2021
1 parent b3ac30c commit b51f32e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/private/DB/ReconnectWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@
class ReconnectWrapper extends \Doctrine\DBAL\Connection {
public const CHECK_CONNECTION_INTERVAL = 60;

private $lastConnectionCheck = null;
private $lastQuery = null;

public function __construct(array $params, Driver $driver, Configuration $config = null, EventManager $eventManager = null) {
parent::__construct($params, $driver, $config, $eventManager);
$this->lastConnectionCheck = time();
$this->lastQuery = time();
}

public function connect() {
$now = time();
$checkTime = $now - self::CHECK_CONNECTION_INTERVAL;

if ($this->lastConnectionCheck > $checkTime || $this->isTransactionActive()) {
if ($this->lastQuery > $checkTime || $this->isTransactionActive()) {
$this->lastQuery = $now;
return parent::connect();
} else {
$this->lastConnectionCheck = $now;
$this->lastQuery = $now;
if (!$this->ping()) {
$this->close();
}
Expand Down

0 comments on commit b51f32e

Please sign in to comment.