-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpClient] Allow setting max persistent connections in CurlHttpClient
#58270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface, | |
// password as the second one; or string like username:password - enabling NTLM auth | ||
'extra' => [ | ||
'curl' => [], // A list of extra curl options indexed by their corresponding CURLOPT_* | ||
'max_connections' => null, // The maximum amount of simultaneously open connections, corresponds to CURLMOPT_MAXCONNECTS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't put it under |
||
], | ||
]; | ||
private static array $emptyDefaults = self::OPTIONS_DEFAULTS + ['auth_ntlm' => null]; | ||
|
@@ -450,7 +451,7 @@ private static function createRedirectResolver(array $options, string $host, int | |
private function ensureState(): CurlClientState | ||
{ | ||
if (!isset($this->multi)) { | ||
$this->multi = new CurlClientState($this->maxHostConnections, $this->maxPendingPushes); | ||
$this->multi = new CurlClientState($this->maxHostConnections, $this->maxPendingPushes, $this->defaultOptions['extra']['max_connections'] ?? null); | ||
$this->multi->logger = $this->logger; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,7 +37,7 @@ final class CurlClientState extends ClientState | |||||
|
||||||
public static array $curlVersion; | ||||||
|
||||||
public function __construct(int $maxHostConnections, int $maxPendingPushes) | ||||||
public function __construct(int $maxHostConnections, int $maxPendingPushes, ?int $maxConnections = null) | ||||||
{ | ||||||
self::$curlVersion ??= curl_version(); | ||||||
|
||||||
|
@@ -52,8 +52,8 @@ public function __construct(int $maxHostConnections, int $maxPendingPushes) | |||||
if (\defined('CURLMOPT_MAX_HOST_CONNECTIONS')) { | ||||||
$maxHostConnections = curl_multi_setopt($this->handle, \CURLMOPT_MAX_HOST_CONNECTIONS, 0 < $maxHostConnections ? $maxHostConnections : \PHP_INT_MAX) ? 0 : $maxHostConnections; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nicolas-grekas Yes, you're right, see #58278. I opened it as a bug fix, if it's not, please let me know. |
||||||
} | ||||||
if (\defined('CURLMOPT_MAXCONNECTS') && 0 < $maxHostConnections) { | ||||||
curl_multi_setopt($this->handle, \CURLMOPT_MAXCONNECTS, $maxHostConnections); | ||||||
if (\defined('CURLMOPT_MAXCONNECTS') && null !== $maxConnections ??= 0 < $maxHostConnections ? $maxHostConnections : null) { | ||||||
curl_multi_setopt($this->handle, \CURLMOPT_MAXCONNECTS, $maxConnections); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of adding a new option, can you try removing this line and see if curl doesn't do better by default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I re-read your description, you tell about it already. Then what about setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nicolas-grekas Unfortunately, setting |
||||||
} | ||||||
|
||||||
// Skip configuring HTTP/2 push when it's unsupported or buggy, see https://bugs.php.net/77535 | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
echo 'Success'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PHP built-in server doesn't support persistent connections.