@@ -731,6 +731,61 @@ The ``RetryableHttpClient`` uses a
731
731
decide if the request should be retried, and to define the waiting time between
732
732
each retry.
733
733
734
+ Retry over different uris
735
+ .........................
736
+
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.
742
+
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());
749
+
750
+ $response = $client->request('GET', 'some-path', [
751
+ 'base_uri' => [
752
+ // first request will use this base uri
753
+ 'http://example.com/a/',
754
+ // if first request fails, the second base uri will be used
755
+ 'http://example.com/b/',
756
+ ],
757
+ ]);
758
+
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::
771
+
772
+ use Symfony\Component\HttpClient\RetryableHttpClient;
773
+
774
+ $client = new RetryableHttpClient(HttpClient::create());
775
+
776
+ $response = $client->request('GET', 'some-path', [
777
+ 'base_uri' => [
778
+ 'http://example.com/a/',
779
+ [
780
+ // base uri passed inside a nested array will be shuffled
781
+ 'http://example.com/b/',
782
+ 'http://example.com/c/',
783
+ ]
784
+ // the order of the non-nested base uris is preserved
785
+ 'http://example.com/d/',
786
+ ],
787
+ ]);
788
+
734
789
HTTP Proxies
735
790
~~~~~~~~~~~~
736
791
0 commit comments