Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/symfony/rate-limiter
Provides a Token Bucket implementation to rate limit input and output in your application
https://github.com/symfony/rate-limiter
component limiter php rate-limiter symfony symfony-component
Last synced: about 1 month ago
JSON representation
Provides a Token Bucket implementation to rate limit input and output in your application
- Host: GitHub
- URL: https://github.com/symfony/rate-limiter
- Owner: symfony
- License: mit
- Created: 2020-09-16T16:15:59.000Z (about 4 years ago)
- Default Branch: 7.1
- Last Pushed: 2024-09-26T09:29:54.000Z (about 2 months ago)
- Last Synced: 2024-09-30T16:04:28.316Z (about 1 month ago)
- Topics: component, limiter, php, rate-limiter, symfony, symfony-component
- Language: PHP
- Homepage: https://symfony.com/rate-limiter
- Size: 292 KB
- Stars: 235
- Watchers: 8
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Rate Limiter Component
======================The Rate Limiter component provides a Token Bucket implementation to
rate limit input and output in your application.Getting Started
---------------```bash
composer require symfony/rate-limiter
``````php
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
}
```Resources
---------* [Contributing](https://symfony.com/doc/current/contributing/index.html)
* [Report issues](https://github.com/symfony/symfony/issues) and
[send Pull Requests](https://github.com/symfony/symfony/pulls)
in the [main Symfony repository](https://github.com/symfony/symfony)