Skip to content

Commit 14adf83

Browse files
author
Kyra Farrow
committed
[HttpClient] Only use CURLMOPT_MAX_HOST_CONNECTIONS & CURL_VERSION_HTTP2 if defined
- CURLMOPT_MAX_HOST_CONNECTIONS is available since PHP 7.0.7 and cURL 7.30.0 - CURL_VERSION_HTTP2 is available since PHP 5.5.24 and 5.6.8 and cURL 7.33.0
1 parent 7304365 commit 14adf83

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

CurlHttpClient.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public function __construct(array $defaultOptions = [], int $maxHostConnections
7070
if (\defined('CURLPIPE_MULTIPLEX')) {
7171
curl_multi_setopt($this->multi->handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
7272
}
73-
curl_multi_setopt($this->multi->handle, CURLMOPT_MAX_HOST_CONNECTIONS, 0 < $maxHostConnections ? $maxHostConnections : PHP_INT_MAX);
73+
if (\defined('CURLMOPT_MAX_HOST_CONNECTIONS')) {
74+
curl_multi_setopt($this->multi->handle, CURLMOPT_MAX_HOST_CONNECTIONS, 0 < $maxHostConnections ? $maxHostConnections : PHP_INT_MAX);
75+
}
7476

7577
// Skip configuring HTTP/2 push when it's unsupported or buggy, see https://bugs.php.net/bug.php?id=77535
7678
if (0 >= $maxPendingPushes || \PHP_VERSION_ID < 70217 || (\PHP_VERSION_ID >= 70300 && \PHP_VERSION_ID < 70304)) {
@@ -188,7 +190,7 @@ public function request(string $method, string $url, array $options = []): Respo
188190
$curlopts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
189191
} elseif (1.1 === (float) $options['http_version'] || 'https:' !== $scheme) {
190192
$curlopts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
191-
} elseif (CURL_VERSION_HTTP2 & curl_version()['features']) {
193+
} elseif (\defined('CURL_VERSION_HTTP2') && CURL_VERSION_HTTP2 & curl_version()['features']) {
192194
$curlopts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0;
193195
}
194196

0 commit comments

Comments
 (0)