Skip to content

Commit

Permalink
bug #31569 [HttpClient] Only use CURLMOPT_MAX_HOST_CONNECTIONS & CURL…
Browse files Browse the repository at this point in the history
…_VERSION_HTTP2 if defined (GawainLynch)

This PR was merged into the 4.3 branch.

Discussion
----------

[HttpClient] Only use CURLMOPT_MAX_HOST_CONNECTIONS & CURL_VERSION_HTTP2 if defined

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Regards the constants:

 - 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

Errors triggered:

> Use of undefined constant CURLMOPT_MAX_HOST_CONNECTIONS - assumed 'CURLMOPT_MAX_HOST_CONNECTIONS'
> in vendor/symfony/http-client/CurlHttpClient.php (line 73)

> Use of undefined constant CURL_VERSION_HTTP2 - assumed 'CURL_VERSION_HTTP2'
> in vendor/symfony/http-client/CurlHttpClient.php (line 191)

Commits
-------

4ea7283 [HttpClient] Only use CURLMOPT_MAX_HOST_CONNECTIONS & CURL_VERSION_HTTP2 if defined
  • Loading branch information
fabpot committed May 22, 2019
2 parents 31ba038 + 4ea7283 commit 274ff66
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Symfony/Component/HttpClient/CurlHttpClient.php
Expand Up @@ -70,7 +70,9 @@ public function __construct(array $defaultOptions = [], int $maxHostConnections
if (\defined('CURLPIPE_MULTIPLEX')) {
curl_multi_setopt($this->multi->handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
}
curl_multi_setopt($this->multi->handle, CURLMOPT_MAX_HOST_CONNECTIONS, 0 < $maxHostConnections ? $maxHostConnections : PHP_INT_MAX);
if (\defined('CURLMOPT_MAX_HOST_CONNECTIONS')) {
curl_multi_setopt($this->multi->handle, CURLMOPT_MAX_HOST_CONNECTIONS, 0 < $maxHostConnections ? $maxHostConnections : PHP_INT_MAX);
}

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

Expand Down

0 comments on commit 274ff66

Please sign in to comment.