8000 [HttpClient] Add doc for multiple `base_uri` as array by Tiriel · Pull Request #18227 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[HttpClient] Add doc for multiple base_uri as array #18227

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

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions http_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,59 @@ The ``RetryableHttpClient`` uses a
decide if the request should be retried, and to define the waiting time between
each retry.

Retry Over Several Base URIs
............................

.. versionadded:: 6.3

The multiple ``base_uri`` feature was added in Symfony 6.3.

The ``RetryableHttpClient`` can be configured to use multiple base URIs. This
feature provides increased flexibility and reliability for making HTTP
requests. Pass an array of base URIs as option ``base_uri`` when making a
request::

$response = $client->request('GET', 'some-page', [
'base_uri' => [
// first request will use this base URI
'https://example.com/a/',
// if first request fails, the following base URI will be used
'https://example.com/b/',
],
]);

When the number of retries is higher than the number of base URIs, the
last base URI will be used for the remaining retries.

If you want to shuffle the order of base URIs for each retry attempt, nest the
base URIs you want to shuffle in an additional array::

$response = $client->request('GET', 'some-page', [
'base_uri' => [
[
// a single random URI from this array will be used for the first request
'https://example.com/a/',
'https://example.com/b/',
],
// non-nested base URIs are used in order
'https://example.com/c/',
],
]);

This feature allows for a more randomized approach to handling retries,
reducing the likelihood of repeatedly hitting the same failed base URI.

By using a nested array for the base URI, you can use this feature
to distribute the load among many nodes in a cluster of servers.

You can also configure the array of base URIs using the ``withOptions()``
method::

$client = $client->withOptions(['base_uri' => [
'https://example.com/a/',
'https://example.com/b/',
]]);

HTTP Proxies
~~~~~~~~~~~~

Expand Down
0