Skip to content

Commit eedba96

Browse files
[10.x] HTTP client doc update for retry backoff option (#9328)
* http client doc update for retry backoff option * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 3b96a5e commit eedba96

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

http-client.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ If you would like the HTTP client to automatically retry the request if a client
231231

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

234+
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:
235+
236+
use Exception;
237+
238+
$response = Http::retry(3, function (int $attempt, Exception $exception) {
239+
return $attempt * 100;
240+
})->post(/* ... */);
241+
242+
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:
243+
244+
$response = Http::retry([100, 200])->post(/* ... */);
245+
234246
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`:
235247

236248
use Exception;

0 commit comments

Comments
 (0)