11Retry Plugin
22============
33
4- The ``RetryPlugin `` can automatically attempt to re-send a request that failed, to work around
5- unreliable connections and servers. It relies on errors to throw exceptions, so you need to
6- place something like the :doc: `ErrorPlugin <error >` later in the plugin chain::
4+ The ``RetryPlugin `` can automatically attempt to re-send a request that failed,
5+ to work around unreliable connections and servers. It re-sends the request when
6+ an exception is thrown, unless the exception is a HttpException for a status
7+ code in the 5xx server error range. Since version 2.0, responses with status
8+ codes in the 5xx range are also retried. Each retry attempt is delayed by an
9+ exponential backoff time.
710
8- use Http\Discovery\HttpClientDiscovery;
9- use Http\Client\Common\PluginClient;
10- use Http\Client\Common\Plugin\ErrorPlugin;
11- use Http\Client\Common\Plugin\RetryPlugin;
12-
13- $pluginClient = new PluginClient(
14- HttpClientDiscovery::find(),
15- [
16- new RetryPlugin(),
17- new ErrorPlugin(),
18- ]
19- );
11+ See below for how to configure that behaviour.
2012
2113.. warning ::
2214
@@ -30,12 +22,51 @@ but simply tries again from the current position.
3022Async
3123-----
3224
33- This plugin is not fully compatible with asynchronous behavior, as the wait between retries is done
34- with a blocking call to a sleep function.
25+ This plugin is not fully compatible with asynchronous behavior, as the wait
26+ between retries is done with a blocking call to a sleep function.
3527
3628Options
3729-------
3830
3931``retries ``: int (default: 1)
4032
4133Number of retry attempts to make before giving up.
34+
35+ ``error_response_decider ``: callable (default behaviour: retry if status code is in 5xx range)
36+
37+ A callback function that receives the request and response to decide whether the
38+ request should be retried.
39+
40+ ``exception_decider ``: callable (default behaviour: retry if the exception is not an HttpException or status code is in 5xx range)
41+
42+ A callback function that receives a request and an exception to decide after a
43+ failure whether the request should be retried.
44+
45+ ``error_response_delay ``: callable (default behaviour: exponential backoff)
46+
47+ A callback that receives a request, a response, the current number of retries
48+ and returns how many microseconds we should wait before trying again.
49+
50+ ``exception_delay ``: callable (default behaviour: exponential backoff)
51+
52+ A callback that receives a request, an exception, the current number of retries
53+ and returns how many microseconds we should wait before trying again.
54+
55+ Interaction with Exceptions
56+ ---------------------------
57+
58+ If you use the :doc: `ErrorPlugin <error >`, you should place it after the RetryPlugin in the
59+ plugin chain::
60+
61+ use Http\Discovery\HttpClientDiscovery;
62+ use Http\Client\Common\PluginClient;
63+ use Http\Client\Common\Plugin\ErrorPlugin;
64+ use Http\Client\Common\Plugin\RetryPlugin;
65+
66+ $pluginClient = new PluginClient(
67+ HttpClientDiscovery::find(),
68+ [
69+ new RetryPlugin(),
70+ new ErrorPlugin(),
71+ ]
72+ );
0 commit comments