symfony/rate-limiter
Provides a Token Bucket implementation to rate limit input and output in your application
Maintainers
v8.1.0
2026-05-29 05:06 UTC
Requires
- php: >=8.4.1
- symfony/options-resolver: ^7.4|^8.0
Requires (Dev)
- psr/cache: ^1.0|^2.0|^3.0
- symfony/lock: ^7.4|^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT 657d5b948e913b3989d9cf2f79a84e44e454345a
- Wouter de Jong <wouter.woop@wouterj.nl>
- Symfony Community
This package is auto-updated.
Last update: 2026-06-09 11:23:05 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 }
Sponsor
This package is looking for a backer.
Help Symfony by sponsoring its development!
