From 7dfaac06e49a9639a3b5d6a5bdf6665640c797bd Mon Sep 17 00:00:00 2001 From: Namoshek Date: Sat, 8 Jan 2022 14:23:13 +0100 Subject: [PATCH] Fix: Recreate disconnected connections when being retrieved (#19) --- src/ConnectionManager.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ConnectionManager.php b/src/ConnectionManager.php index eb6a60c..b3688bc 100644 --- a/src/ConnectionManager.php +++ b/src/ConnectionManager.php @@ -60,6 +60,12 @@ class ConnectionManager $name = $this->defaultConnection; } + // Remove the connection if it is in a disconnected state. + // Doing this instead of simply reconnecting ensures the caller will get a fresh connection. + if (array_key_exists($name, $this->connections) && !$this->connections[$name]->isConnected()) { + unset($this->connections[$name]); + } + if (!array_key_exists($name, $this->connections)) { $this->connections[$name] = $this->createConnection($name); }