Skip to content

Commit 8fe2f2f

Browse files
committed
[HttpClient] Fix setting CURLMOPT_MAXCONNECTS
1 parent e104cd2 commit 8fe2f2f

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

.github/workflows/integration-tests.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ jobs:
118118
KAFKA_CFG_LISTENERS: 'PLAINTEXT://:9092'
119119
KAFKA_CFG_ZOOKEEPER_CONNECT: 'zookeeper:2181'
120120
options: --name=kafka
121+
frankenphp:
122+
image: dunglas/frankenphp:1.1.0
123+
ports:
124+
- 80:80
125+
- 8681:81
126+
- 8682:82
127+
- 8683:83
128+
- 8684:84
129+
volumes:
130+
- ${{ github.workspace }}:/symfony
131+
env:
132+
SERVER_NAME: 'http://localhost http://localhost:81 http://localhost:82 http://localhost:83 http://localhost:84'
133+
CADDY_SERVER_EXTRA_DIRECTIVES: |
134+
route /http-client* {
135+
root * /symfony/src/Symfony/Component/HttpClient/Tests/Fixtures/response-functional/
136+
php_server
137+
}
121138
122139
steps:
123140
- name: Checkout

src/Symfony/Component/HttpClient/Internal/CurlClientState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(int $maxHostConnections, int $maxPendingPushes)
5353
curl_multi_setopt($this->handle, \CURLMOPT_PIPELINING, \CURLPIPE_MULTIPLEX);
5454
}
5555
if (\defined('CURLMOPT_MAX_HOST_CONNECTIONS')) {
56-
$maxHostConnections = curl_multi_setopt($this->handle, \CURLMOPT_MAX_HOST_CONNECTIONS, 0 < $maxHostConnections ? $maxHostConnections : \PHP_INT_MAX) ? 0 : $maxHostConnections;
56+
$maxHostConnections = curl_multi_setopt($this->handle, \CURLMOPT_MAX_HOST_CONNECTIONS, 0 < $maxHostConnections ? $maxHostConnections : \PHP_INT_MAX) ? 4294967295 : $maxHostConnections;
5757
}
5858
if (\defined('CURLMOPT_MAXCONNECTS') && 0 < $maxHostConnections) {
5959
curl_multi_setopt($this->handle, \CURLMOPT_MAXCONNECTS, $maxHostConnections);

src/Symfony/Component/HttpClient/Tests/CurlHttpClientTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,34 @@ public function testKeepAuthorizationHeaderOnRedirectToSameHostWithConfiguredHos
144144
$this->assertSame(200, $response->getStatusCode());
145145
$this->assertSame('/302', $response->toArray()['REQUEST_URI'] ?? null);
146146
}
147+
148+
/**
149+
* @group integration
150+
*/
151+
public function testMaxConnections()
152+
{
153+
foreach ($ports = [80, 8681, 8682, 8683, 8684] as $port) {
154+
if (!($fp = @fsockopen('localhost', $port, $errorCode, $errorMessage, 2))) {
155+
self::markTestSkipped('FrankenPHP is not running');
156+
}
157+
fclose($fp);
158+
}
159+
160+
$httpClient = $this->getHttpClient(__FUNCTION__);
161+
162+
$expectedResults = [
163+
[false, false, false, false, false],
164+
[true, true, true, true, true],
165+
[true, true, true, true, true],
166+
];
167+
168+
foreach ($expectedResults as $expectedResult) {
169+
foreach ($ports as $i => $port) {
170+
$response = $httpClient->request('GET', \sprintf('http://localhost:%s/http-client', $port));
171+
$response->getContent();
172+
173+
self::assertSame($expectedResult[$i], str_contains($response->getInfo('debug'), 'Re-using existing connection'));
174+
}
175+
}
176+
}
147177
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
echo 'Success';

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy