Skip to content

Commit ee6bc94

Browse files
committed
Force closing a persistent connection via StreamConnection::close()
This is necessary in cases of "out-of-sync" errors or when re-authentication is required. How to test/reproduce: // test_auth.php <?php // Run php -S localhost:8000 test_auth.php, // then open the http://localhost:8000/?close=0 page // and then http://localhost:8000/?close=1 // (authentication must be initiated for both requests) declare(strict_types=1); use Tarantool\Client\Client; use Tarantool\Client\Middleware\AuthenticationMiddleware; require __DIR__.'/vendor/autoload.php'; $client = Client::fromDsn('tcp://localhost:3301?persistent=true'); $client = $client->withMiddleware(new AuthenticationMiddleware('guest')); if (isset($_REQUEST['close']) && $_REQUEST['close']) { $client->getHandler()->getConnection()->close(); } $client->ping();
1 parent c409cc4 commit ee6bc94

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Connection/Connection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface Connection
2727
public function open() : Greeting;
2828

2929
/**
30-
* Closes an opened connection.
30+
* Closes an opened connection (including a persistent one).
3131
*/
3232
public function close() : void;
3333

src/Connection/StreamConnection.php

+6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ public function open() : Greeting
119119

120120
public function close() : void
121121
{
122+
// To close a previously opened persistent connection,
123+
// we need to obtain its stream handler first
124+
if (!$this->stream && $this->options['persistent']) {
125+
$this->open();
126+
}
127+
122128
if ($this->stream) {
123129
/** @psalm-suppress InvalidPropertyAssignmentValue */
124130
\fclose($this->stream);

0 commit comments

Comments
 (0)