Skip to content

Commit

Permalink
[10.x] HTTP client doc update for retry backoff option (#9328)
Browse files Browse the repository at this point in the history
* http client doc update for retry backoff option

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
me-shaon and taylorotwell authored Feb 13, 2024
1 parent 3b96a5e commit eedba96
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions http-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@ If you would like the HTTP client to automatically retry the request if a client

$response = Http::retry(3, 100)->post(/* ... */);

If you would like to manually calculate the number of milliseconds to sleep between attempts, you may pass a closure as the second argument to the `retry` method:

use Exception;

$response = Http::retry(3, function (int $attempt, Exception $exception) {
return $attempt * 100;
})->post(/* ... */);

For convenience, you may also provide an array as the first argument to the `retry` method. This array will be used to determine how many milliseconds to sleep between subsequent attempts:

$response = Http::retry([100, 200])->post(/* ... */);

If needed, you may pass a third argument to the `retry` method. The third argument should be a callable that determines if the retries should actually be attempted. For example, you may wish to only retry the request if the initial request encounters an `ConnectionException`:

use Exception;
Expand Down

0 comments on commit eedba96

Please sign in to comment.