Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "expensify/bedrock-php",
"description": "Bedrock PHP Library",
"type": "library",
"version": "2.1.0",
"version": "2.1.1",
"authors": [
{
"name": "Expensify",
Expand Down
20 changes: 18 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,21 @@ class Client implements LoggerAwareInterface
*/
private $connectionTimeout;

/**
* @var int Microsecond timeout for connecting to the server.
*/
private $connectionTimeoutMicroseconds;

/**
* @var int Timeout for reading the response from the server.
*/
private $readTimeout;

/**
* @var int Microsecond timeout for reading the response from the server.
*/
private $readTimeoutMicroseconds;

/**
* @var int Timeout to pass to bedrock.
*/
Expand Down Expand Up @@ -149,7 +159,9 @@ class Client implements LoggerAwareInterface
* array|null mainHostConfigs List of hosts to attempt first
* array|null failovers List of hosts to use as failovers
* int|null connectionTimeout Timeout to use when connecting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this after the transition period?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do some tests to see if you can pass a timeout of several seconds in the useconds param or if it is just for the subsecond part of the timeout.

Copy link
Contributor Author

@iwiznia iwiznia Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* int|null connectionTimeoutMicroseconds Microsecond timeout to use when connecting
* int|null readTimeout Timeout to use when reading
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

* int|null readTimeoutMicroseconds Microsecond timeout to use when reading
* int|null bedrockTimeout Timeout to use for bedrock commands
* LoggerInterface|null logger Class to use for logging
* StatsInterface|null stats Class to use for statistics tracking
Expand All @@ -167,7 +179,9 @@ private function __construct(array $config = [])
$this->mainHostConfigs = $config['mainHostConfigs'];
$this->failoverHostConfigs = $config['failoverHostConfigs'];
$this->connectionTimeout = $config['connectionTimeout'];
$this->connectionTimeoutMicroseconds = $config['connectionTimeoutMicroseconds'];
$this->readTimeout = $config['readTimeout'];
$this->readTimeoutMicroseconds = $config['readTimeoutMicroseconds'];
$this->bedrockTimeout = $config['bedrockTimeout'];
$this->logger = $config['logger'];
$this->stats = $config['stats'];
Expand Down Expand Up @@ -241,7 +255,9 @@ public static function configure(array $config)
'mainHostConfigs' => ['localhost' => ['blacklistedUntil' => 0, 'port' => 8888]],
'failoverHostConfigs' => ['localhost' => ['blacklistedUntil' => 0, 'port' => 8888]],
'connectionTimeout' => 1,
'connectionTimeoutMicroseconds' => 0,
'readTimeout' => 120,
'readTimeoutMicroseconds' => 0,
'bedrockTimeout' => 110,
'logger' => new NullLogger(),
'stats' => new NullStats(),
Expand Down Expand Up @@ -531,8 +547,8 @@ private function sendRawRequest(string $host, int $port, string $rawRequest)
}

// Configure this socket and try to connect to it
socket_set_option($this->socket, SOL_SOCKET, SO_SNDTIMEO, ['sec' => $this->connectionTimeout, 'usec' => 0]);
socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, ['sec' => $this->readTimeout, 'usec' => 0]);
socket_set_option($this->socket, SOL_SOCKET, SO_SNDTIMEO, ['sec' => $this->connectionTimeout, 'usec' => $this->connectionTimeoutMicroseconds]);
socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, ['sec' => $this->readTimeout, 'usec' => $this->readTimeoutMicroseconds]);
@socket_connect($this->socket, $host, $port);
$socketErrorCode = socket_last_error($this->socket);
if ($socketErrorCode === 115) {
Expand Down