Skip to content

Commit d418abd

Browse files
CopilotThavarshan
andcommitted
Simplify metrics incrementing, improve curl options comment
Co-authored-by: Thavarshan <10804999+Thavarshan@users.noreply.github.com>
1 parent d049cab commit d418abd

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/Fetch/Concerns/ManagesConnectionPool.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public function withHttp2(array|bool $config = true): ClientHandler
8181
$curlOptions = $this->http2Config->getCurlOptions();
8282
if (! empty($curlOptions)) {
8383
$existingCurl = $this->options['curl'] ?? [];
84-
// Use + operator to preserve integer keys
84+
// Use + operator to preserve integer keys (CURL constants)
85+
// and give priority to existing options over defaults
8586
$this->options['curl'] = $existingCurl + $curlOptions;
8687
}
8788

src/Fetch/Pool/ConnectionPool.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function getConnection(string $host, int $port = 80, bool $ssl = false):
8282
$this->activeConnections[spl_object_id($connection)] = $connection;
8383

8484
// Update metrics
85-
$this->metrics['total_requests'] = (int) $this->metrics['total_requests'] + 1;
85+
$this->metrics['total_requests']++;
8686

8787
return $connection;
8888
}
@@ -122,7 +122,7 @@ public function releaseConnection(Connection $connection): void
122122

123123
if (isset($this->pools[$poolKey])) {
124124
$this->pools[$poolKey]->returnConnection($connection);
125-
$this->metrics['connections_reused'] = (int) $this->metrics['connections_reused'] + 1;
125+
$this->metrics['connections_reused']++;
126126
} else {
127127
$connection->close();
128128
}
@@ -169,7 +169,7 @@ public function getClientForUrl(string $url): ?ClientInterface
169169
*/
170170
public function recordLatency(string $host, int $port, float $latency): void
171171
{
172-
$this->metrics['total_latency'] = (float) $this->metrics['total_latency'] + $latency;
172+
$this->metrics['total_latency'] += $latency;
173173
}
174174

175175
/**

0 commit comments

Comments
 (0)