Skip to content

Commit

Permalink
Merge pull request #533 from utopia-php/feat-auto-reconnect
Browse files Browse the repository at this point in the history
Add log on reconnect
  • Loading branch information
abnegate authored Mar 5, 2025
2 parents fe0e975 + 08d0e12 commit f3c9aa9
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Database/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Utopia\Database;

use Swoole\Database\DetectsLostConnections;
use Utopia\CLI\Console;

/**
* A PDO wrapper that forwards method calls to the internal PDO instance.
Expand Down Expand Up @@ -46,6 +47,7 @@ public function __call(string $method, array $args): mixed
} catch (\Throwable $e) {
/** @phpstan-ignore-next-line can't find static method */
if (DetectsLostConnections::causedByLostConnection($e)) {
Console::warning('[Database] Lost connection detected. Reconnecting...');
$this->reconnect();
return $this->pdo->{$method}(...$args);
}
Expand Down

0 comments on commit f3c9aa9

Please sign in to comment.