Download the PHP package yiisoft/rate-limiter without Composer
On this page you can find all versions of the php package yiisoft/rate-limiter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yiisoft/rate-limiter
More information about yiisoft/rate-limiter
Files in yiisoft/rate-limiter
Package rate-limiter
Short Description Yii Rate Limiter Middleware
License BSD-3-Clause
Homepage https://www.yiiframework.com/
Informations about the package rate-limiter
Yii Rate Limiter Middleware
Rate limiter middleware helps to prevent abuse by limiting the number of requests that could be me made consequentially.
For example, you may want to limit the API usage of each user to be at most 100 API calls within a period of 10 minutes. If too many requests are received from a user within the stated period of the time, a response with status code 429 (meaning "Too Many Requests") should be returned.
Requirements
- PHP 8.0 or higher.
Installation
The package could be installed with Composer:
General usage
In the above 2 is the maximum number of counter increments (requests) that could be performed before increments are limited and 5 is a period to apply limit to, in seconds.
The Counter
implements generic cell rate limit algorithm (GCRA)
that ensures that after reaching the limit further increments are distributed equally.
Note: While it is sufficiently effective, it is preferred to use Nginx or another webserver capabilities for rate limiting. This package allows rate-limiting in the project with deployment environment you cannot control such as installable CMS.
Implementing your own limiting policy
There are two ready to use limiting policies available in the package:
LimitAlways
- to count all incoming requests.LimitPerIp
- to count requests from different IPs separately.
These could be applied as follows:
Easiest way to customize a policy is to use LimitCallback
:
Another way it to implement Yiisoft\Yii\RateLimiter\Policy\LimitPolicyInterface
and use it in a similar way as above.
Implementing your own counter storage
There are two ready to use counter storages available in the package:
\Yiisoft\Yii\RateLimiter\Storage\SimpleCacheStorage
- stores counters in any PSR-16 cache.\Yiisoft\Yii\RateLimiter\Storage\ApcuStorage
- stores counters by using the APCu PHP extension while taking concurrency into account.
To use your own storage implement Yiisoft\Yii\RateLimiter\Storage\StorageInterface
.
Documentation
- Internals
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Rate Limiter Middleware is free software. It is released under the terms of the BSD License.
Please see LICENSE
for more information.
Maintained by Yii Software.
Support the project
Follow updates
All versions of rate-limiter with dependencies
psr/http-factory Version ^1.0
psr/http-message Version ^1.1|^2.0
psr/http-message-implementation Version 1.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
psr/simple-cache Version ^2.0|^3.0
yiisoft/http Version ^1.2