symfony / rate-limiter
Provides a Token Bucket implementation to rate limit input and output in your application
Fund package maintenance!
fabpot
Tidelift
symfony.com/sponsor
Requires
- php: >=8.2
- symfony/options-resolver: ^6.4|^7.0
Requires (Dev)
- psr/cache: ^1.0|^2.0|^3.0
- symfony/lock: ^6.4|^7.0
- 7.2.x-dev
- v7.2.0-RC1
- v7.2.0-BETA2
- v7.2.0-BETA1
- 7.1.x-dev
- v7.1.8
- v7.1.7
- v7.1.6
- v7.1.1
- v7.1.0
- v7.1.0-RC1
- v7.1.0-BETA1
- 7.0.x-dev
- v7.0.8
- v7.0.7
- v7.0.3
- v7.0.2
- v7.0.0
- v7.0.0-RC1
- v7.0.0-BETA3
- v7.0.0-BETA1
- 6.4.x-dev
- v6.4.15
- v6.4.14
- v6.4.13
- v6.4.8
- v6.4.7
- v6.4.3
- v6.4.2
- v6.4.0
- v6.4.0-RC1
- v6.4.0-BETA3
- v6.4.0-BETA1
- 6.3.x-dev
- v6.3.12
- v6.3.11
- v6.3.8
- v6.3.6
- v6.3.2
- v6.3.0
- v6.3.0-RC1
- v6.3.0-BETA1
- 6.2.x-dev
- v6.2.13
- v6.2.7
- v6.2.5
- v6.2.2
- v6.2.0
- v6.2.0-RC1
- v6.2.0-BETA1
- 6.1.x-dev
- v6.1.11
- v6.1.9
- v6.1.3
- v6.1.0
- v6.1.0-RC1
- v6.1.0-BETA1
- 6.0.x-dev
- v6.0.19
- v6.0.17
- v6.0.11
- v6.0.9
- v6.0.8
- v6.0.7
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
- v6.0.0-RC1
- v6.0.0-BETA3
- v6.0.0-BETA1
- 5.4.x-dev
- v5.4.47
- v5.4.46
- v5.4.45
- v5.4.40
- v5.4.39
- v5.4.35
- v5.4.30
- v5.4.26
- v5.4.21
- v5.4.19
- v5.4.17
- v5.4.11
- v5.4.9
- v5.4.8
- v5.4.7
- v5.4.3
- v5.4.2
- v5.4.0
- v5.4.0-RC1
- v5.4.0-BETA3
- v5.4.0-BETA1
- 5.3.x-dev
- v5.3.14
- v5.3.13
- v5.3.11
- v5.3.4
- v5.3.0
- v5.3.0-RC1
- v5.3.0-BETA1
- 5.2.x-dev
- v5.2.12
- v5.2.10
- v5.2.7
- v5.2.6
- v5.2.4
- v5.2.3
- v5.2.2
- v5.2.1
- v5.2.0
- v5.2.0-RC2
- v5.2.0-RC1
- v5.2.0-BETA3
- v5.2.0-BETA2
- v5.2.0-BETA1
This package is auto-updated.
Last update: 2024-11-13 15:17:04 UTC
README
The Rate Limiter component provides a Token Bucket implementation to rate limit input and output in your application.
Getting Started
composer require symfony/rate-limiter
use Symfony\Component\RateLimiter\Storage\InMemoryStorage; use Symfony\Component\RateLimiter\RateLimiterFactory; $factory = new RateLimiterFactory([ 'id' => 'login', 'policy' => 'token_bucket', 'limit' => 10, 'rate' => ['interval' => '15 minutes'], ], new InMemoryStorage()); $limiter = $factory->create(); // blocks until 1 token is free to use for this process $limiter->reserve(1)->wait(); // ... execute the code // only claims 1 token if it's free at this moment (useful if you plan to skip this process) if ($limiter->consume(1)->isAccepted()) { // ... execute the code }