From ac55a9cf0a3980d738b35712e17c8293480c946b Mon Sep 17 00:00:00 2001 From: Ahmed shamim Date: Tue, 13 Feb 2024 21:57:19 +0600 Subject: [PATCH 1/2] http client doc update for retry backoff option --- http-client.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/http-client.md b/http-client.md index 43dfb9f004f..e0ad15242cf 100644 --- a/http-client.md +++ b/http-client.md @@ -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 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; From b39593b7f91b70eb9b433d752cdd48912b8f5e62 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 13 Feb 2024 15:59:40 -0600 Subject: [PATCH 2/2] formatting --- http-client.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http-client.md b/http-client.md index e0ad15242cf..c172dc8a31c 100644 --- a/http-client.md +++ b/http-client.md @@ -239,7 +239,7 @@ If you would like to manually calculate the number of milliseconds to sleep betw return $attempt * 100; })->post(/* ... */); -For convenience, you may 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: +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(/* ... */);