@@ -1474,6 +1474,40 @@ installed in your application::
1474
1474
:class: `Symfony\\ Component\\ HttpClient\\ CachingHttpClient ` accepts a third argument
1475
1475
to set the options of the :class: `Symfony\\ Component\\ HttpKernel\\ HttpCache\\ HttpCache `.
1476
1476
1477
+ Limit the Number of Requests
1478
+ ----------------------------
1479
+
1480
+ This component provides a :class: `Symfony\\ Component\\ HttpClient\\ ThrottlingHttpClient `
1481
+ decorator that allows to limit the number of requests within a certain period.
1482
+
1483
+ The implementation leverages the
1484
+ :class: `Symfony\\ Component\\ RateLimiter\\ LimiterInterface ` class under the hood
1485
+ so that the :doc: `Rate Limiter component </rate_limiter >` needs to be
1486
+ installed in your application::
1487
+
1488
+ use Symfony\Component\HttpClient\HttpClient;
1489
+ use Symfony\Component\HttpClient\ThrottlingHttpClient;
1490
+ use Symfony\Component\RateLimiter\LimiterInterface;
1491
+
1492
+ $rateLimiter = ...; // $rateLimiter is an instance of Symfony\Component\RateLimiter\LimiterInterface
1493
+ $client = HttpClient::create();
1494
+ $client = new ThrottlingHttpClient($client, $rateLimiter);
1495
+
1496
+ $requests = [];
1497
+ for ($i = 0; $i < 100; $i++) {
1498
+ $requests[] = $client->request('GET', 'https://example.com');
1499
+ }
1500
+
1501
+ foreach ($requests as $request) {
1502
+ // Depending on rate limiting policy, calls will be delayed
1503
+ $output->writeln($request->getContent());
1504
+ }
1505
+
1506
+ .. versionadded :: 7.1
1507
+
1508
+ The :class: `Symfony\\ Component\\ HttpClient\\ ThrottlingHttpClient ` was
1509
+ introduced in Symfony 7.1.
1510
+
1477
1511
Consuming Server-Sent Events
1478
1512
----------------------------
1479
1513
0 commit comments