Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Commit

Permalink
Allow to deactivate persist flag on client connections
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwurtz committed Nov 7, 2019
1 parent d4073d0 commit 64c278f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ class Client
private $logger;
private $currentConnection;
private $currentConnectionName;
private $persist;

/**
* @param int $timeout
* @param bool $debug
*/
public function __construct(string $projectKey, array $connections, $timeout = 10000, $debug = false, LoggerInterface $logger = null)
public function __construct(string $projectKey, array $connections, $timeout = 10000, $debug = false, LoggerInterface $logger = null, $persist = true)
{
if (!$projectKey) {
throw new BadConfigurationException('A project key is required.');
Expand All @@ -47,6 +48,7 @@ public function __construct(string $projectKey, array $connections, $timeout = 1
$this->timeout = $timeout;
$this->debug = $debug;
$this->logger = $logger ?: new NullLogger();
$this->persist = $persist;
}

public function request(Command\CommandInterface $command)
Expand Down Expand Up @@ -171,12 +173,18 @@ private function doConnect($options)
$context = stream_context_create();
}

$flags = STREAM_CLIENT_CONNECT;

if ($this->persist) {
$flags |= STREAM_CLIENT_PERSISTENT;
}

$connection = stream_socket_client(
$options['remote_socket'],
$errNo,
$errMsg,
1, // This value is not used but it should not be 0
STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT,
$flags,
$context
);

Expand Down

0 comments on commit 64c278f

Please sign in to comment.