-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[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 yo 8000 ur account
[HttpClient] Add doc for multiple base_uri
as array
#18227
Conversation
Is the failed build normal? It doesn't seem related to my changes, and seems to affect other PRs towards 6.3 but I'm not sure. |
A I think we can make this a bit shorter and more straight to the point: 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:
.. code-block:: php
$response = $client->request('GET', 'foo-bar', [
'base_uri' => [
'http://example.com/a/', // first request will use this base URI
'http://example.com/b/', // if first request fails, this second base URI will be used
],
]);
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:
.. code-block:: php
$response = $client->request('GET', 'foo-bar', [
'base_uri' => [
'http://example.com/a/',
[
'http://example.com/b/', // one random URI from this list will be used on retry #2
'http://example.com/c/',
],
'http://example.com/d/', // non-nested base URIs are used in order
],
]);
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 first base URI, you can use this feature to distribute the load among many nodes in a cluster of servers.
When the number of retries is higher than the number of base URIs, the last base URI will be used for remaining retries.
You can also configure the array of base URIs using the ``withOptions()`` method:
.. code-block:: php
$client = $client->withOptions(['base_uri' => [
'http://example.com/a/',
'http://example.com/b/',
]]); |
Yeah, indeed, sorry! Should I put the entire block inside the
Ok, wil change this during break! |
Just curious about one thing:
It's not just for the first base URI unless I misunderstood one of your modifications. Or did I miss something? |
retries should be rare, so that randomizing only the second base URI wouldn't provide load balancing |
Okay got it, thanks! Was just to be sure though. Technically speaking, it works on any key of the array but it should be extremely rare to use it on subsequent keys indeed. |
ba34ef2
to
56d310e
Compare
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.
Merge remote-tracking
never merge, always rebase
Okay sorry, going back for a rebase! |
56d310e
to
83ec702
Compare
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.
After my comments
base_uri
as array
ca1b333
to
b1c1a84
Compare
b1c1a84
to
7244375
Compare
Thanks Benjamin for working on this feature, this is much appreciated and congratulations on your first contribution to the Symfony documentation 🎉 |
Add documentation for multiple base_uris in HttpClient (Symfony PR (merged): symfony/symfony#49809 )
Fixes #18224