Download the PHP package tal7aouy/api-rate-limiter without Composer
On this page you can find all versions of the php package tal7aouy/api-rate-limiter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tal7aouy/api-rate-limiter
More information about tal7aouy/api-rate-limiter
Files in tal7aouy/api-rate-limiter
Package api-rate-limiter
Short Description API Rate Limiting Library for PHP
License MIT
Informations about the package api-rate-limiter
API Rate Limiting Library
This library provides rate limiting functionality for PHP applications, using Redis for storage. It supports multiple rate limiting strategies and can be integrated with PSR-15 middleware.
Installation
To use the library, you need to have the following Composer packages, which are already included in the library's composer.json
file:
predis/predis
- A Redis client library.laminas/laminas-diactoros
- Provides PSR-7 (HTTP message) and PSR-15 (HTTP server) implementations.psr/http-server-handler
- Provides theRequestHandlerInterface
for handling HTTP requests.psr/http-server-middleware
- Provides theMiddlewareInterface
for HTTP middleware.laminas/laminas-httphandlerrunner
- Provides theSapiEmitter
class for emitting HTTP responses.
In addition, for development and testing, the library includes:
phpstan/phpstan
- For static analysis.pestphp/pest
- For testing.
Install Library and Dependencies
Run the following Composer command to install all required packages:
Ensure Redis is installed and running on your system.
Usage
Basic Setup
-
Initialize Redis Connection:
Create a
RedisConnection
instance to handle the connection to the Redis server. -
Initialize Redis Rate Limiter:
Create a
RedisRateLimiter
instance using the Redis connection. -
Initialize Rate Limiter Middleware:
Create a
RateLimiterMiddleware
instance with the desired rate limit and time window. -
Create a Request Handler:
Implement a simple request handler to handle incoming requests.
-
Create Server Request and Process Through Middleware:
Create a server request and process it through the rate limiter middleware.
Advanced Configuration
Custom Redis Configuration
You can configure the Redis connection by passing a custom configuration array to the RedisConnection
class.
Custom Rate Limiting Strategies
The library supports multiple rate limiting strategies. You can implement your own strategy by extending the RateLimiter
interface.
Then use the custom rate limiter with the middleware.
Testing
Unit tests are provided for each rate limiting strategy and Redis integration. To run the tests, use PestPHP.
Documentation
For detailed documentation and examples, please refer to the source code and comments within the library.
In the examples/index.php
file, you can see a complete example of how to use the library.
Contributing
Contributions are welcome! Please fork the repository and submit a pull request.
License
This software licensed under the MIT license.
All versions of api-rate-limiter with dependencies
predis/predis Version ^2.2
laminas/laminas-diactoros Version ^3.3
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
laminas/laminas-httphandlerrunner Version ^2.10