diff --git a/src/Connection/Connection.php b/src/Connection/Connection.php index 1faf1aea..4a83ecbb 100644 --- a/src/Connection/Connection.php +++ b/src/Connection/Connection.php @@ -27,7 +27,7 @@ interface Connection public function open() : Greeting; /** - * Closes an opened connection. + * Closes an opened connection (including a persistent one). */ public function close() : void; diff --git a/src/Connection/StreamConnection.php b/src/Connection/StreamConnection.php index a59f9b02..499c3136 100644 --- a/src/Connection/StreamConnection.php +++ b/src/Connection/StreamConnection.php @@ -119,6 +119,12 @@ public function open() : Greeting public function close() : void { + // To close a previously opened persistent connection, + // we need to obtain its stream handler first + if (!$this->stream && $this->options['persistent']) { + $this->open(); + } + if ($this->stream) { /** @psalm-suppress InvalidPropertyAssignmentValue */ \fclose($this->stream);