Skip to content

Commit 9563643

Browse files
committed
Rewording
1 parent 462eeff commit 9563643

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

http_client.rst

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -734,58 +734,59 @@ each retry.
734734
Retry over different uris
735735
.........................
736736

737-
When using a ``RetryableHttpClient``, the ``base_uri`` can be set as an array of
738-
uris. The array will be used in the given order, meaning that the first request
739-
will be made with the first uri in the array. Should it fail, the next one will
740-
be used for the first retry. If the number of configured retries is greater than
741-
the number of given uris, the last uri will be used for every exceding retry.
737+
The ``RetryableHttpClient`` can be configured to use multiple base URIs. This
738+
feature provides increased flexibility and reliability for making HTTP
739+
requests. Pass an array of base URIs as option ``base_uri`` when making a
740+
request:
742741

743-
You can pass the array of base uris directly to the ``request`` method or when
744-
creating a HttpClient with the ``withOptions`` method::
745-
746-
use Symfony\Component\HttpClient\RetryableHttpClient;
747-
748-
$client = new RetryableHttpClient(HttpClient::create());
742+
.. code-block:: php
749743
750-
$response = $client->request('GET', 'some-path', [
744+
$response = $client->request('GET', 'foo-bar', [
751745
'base_uri' => [
752-
// first request will use this base uri
746+
// first request will use this base URI
753747
'http://example.com/a/',
754-
// if first request fails, the second base uri will be used
748+
// if first request fails, this second base URI will be used
755749
'http://example.com/b/',
756750
],
757751
]);
758752
759-
// You can also use the withOptions method to pass an array of base_uri
760-
$client = $client->withOptions(['base_uri' => [
761-
'http://example.com/a/',
762-
'http://example.com/b/',
763-
]]);
764-
765-
$response = $client->request('GET', 'some-path');
766-
767-
If you wish some or all of the base uris to be shuffled, you can pass a nested
768-
array inside the ``base_uri`` array. Every uri inside the nested array will be
769-
randomized, and the order of the base uris outside this nested array will be
770-
preserved::
753+
When the number of retries is higher than the number of base URIs, the
754+
last base URI will be used for remaining retries.
771755

772-
use Symfony\Component\HttpClient\RetryableHttpClient;
756+
If you want to shuffle the order of base URIs for each retry attempt, nest the
757+
base URIs you want to shuffle in an additional array:
773758

774-
$client = new RetryableHttpClient(HttpClient::create());
759+
.. code-block:: php
775760
776-
$response = $client->request('GET', 'some-path', [
761+
$response = $client->request('GET', 'foo-bar', [
777762
'base_uri' => [
778763
'http://example.com/a/',
779764
[
780-
// base uri passed inside a nested array will be shuffled
765+
// one random URI from this list will be used on retry #2
781766
'http://example.com/b/',
782767
'http://example.com/c/',
783768
],
784-
// the order of the non-nested base uris is preserved
769+
// non-nested base URIs are used in order
785770
'http://example.com/d/',
786771
],
787772
]);
788773
774+
This feature allows for a more randomized approach to handling retries,
775+
reducing the likelihood of repeatedly hitting the same failed base URI.
776+
777+
By using a nested array for the base URI, you can use this feature
778+
to distribute the load among many nodes in a cluster of servers.
779+
780+
You can also configure the array of base URIs using the ``withOptions()``
781+
method:
782+
783+
.. code-block:: php
784+
785+
$client = $client->withOptions(['base_uri' => [
786+
'http://example.com/a/',
787+
'http://example.com/b/',
788+
]]);
789+
789790
HTTP Proxies
790791
~~~~~~~~~~~~
791792

0 commit comments

Comments
 (0)