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 yo 8000 ur account

Merged
merged 1 commit into from
Apr 20, 2023

Conversation

Tiriel
Copy link
Contributor
@Tiriel Tiriel commented Apr 20, 2023

Add documentation for multiple base_uris in HttpClient (Symfony PR (merged): symfony/symfony#49809 )
Fixes #18224

@Tiriel
Copy link
Contributor Author
Tiriel commented 8000 Apr 20, 2023

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.

@nicolas-grekas
Copy link
Member
nicolas-grekas commented Apr 20, 2023

A versionadded is missing I suppose.

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/',
    ]]);

@Tiriel
Copy link
Contributor Author
Tiriel commented Apr 20, 2023

A versionadded is missing I suppose.

Yeah, indeed, sorry! Should I put the entire block inside the versionadded or only a small phrase explaining it's been added just now?

I think we can make this a bit shorter and more straight to the point:

Ok, wil change this during break!

@Tiriel
Copy link
Contributor Author
Tiriel commented Apr 20, 2023

Just curious about one thing:

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.

It's not just for the first base URI unless I misunderstood one of your modifications. Or did I miss something?

@nicolas-grekas
Copy link
Member

It's not just for the first base URI

retries should be rare, so that randomizing only the second base URI wouldn't provide load balancing

@Tiriel
Copy link
Contributor Author
Tiriel commented Apr 20, 2023

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.
But I do spotted some odd behaviour by looking again (see here )

@Tiriel Tiriel force-pushed the feature/httpclient_multiple_baseuri branch from ba34ef2 to 56d310e Compare April 20, 2023 11:28
Copy link
Member
@nicolas-grekas nicolas-grekas left a 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

@Tiriel
Copy link
Contributor Author
Tiriel commented Apr 20, 2023

never merge, always rebase

Okay sorry, going back for a rebase!

@Tiriel Tiriel force-pushed the feature/httpclient_multiple_baseuri branch from 56d310e to 83ec702 Compare April 20, 2023 11:40
Copy link
Contributor
@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After my comments

@OskarStark OskarStark changed the title [HttpClient] Add doc for multiple base_uri as array [HttpClient] Add doc for multiple base_uri as array Apr 20, 2023
@Tiriel Tiriel force-pushed the feature/httpclient_multiple_baseuri branch 2 times, most recently from ca1b333 to b1c1a84 Compare April 20, 2023 12:26
@OskarStark OskarStark force-pushed the feature/httpclient_multiple_baseuri branch from b1c1a84 to 7244375 Compare April 20, 2023 12:34
@OskarStark
Copy link
Contributor
OskarStark commented Apr 20, 2023

Thanks Benjamin for working on this feature, this is much appreciated and congratulations on your first contribution to the Symfony documentation 🎉

@OskarStark OskarStark merged commit c63db2b into symfony:6.3 Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0