fet/laminas-rate-limiting
最新稳定版本:0.3.0
Composer 安装命令:
composer require fet/laminas-rate-limiting
包简介
A rate limiting module for Laminas MVC applications.
README 文档
README
The fet/laminas-rate-limiting package provides a rate limiting solution for Laminas MVC applications. It allows you to set limits on how often certain routes can be accessed within a specified time window.
Installation
To install this package, use Composer:
composer require fet/laminas-rate-limiting
Make sure you have Composer installed on your system before running this command.
Enable the Fet\LaminasRateLimiting module in your config/application.config.php file.
return [ // ... other modules ... 'Fet\\LaminasRateLimiting', ];
Configuration
Define your rate limiting rules in your module.config.php or global configuration file.
return [ 'rate_limiting' => [ 'enabled' => true, // indicates whether rate limiting is enabled 'max_requests' => 100, // max number of requests 'window' => 60, // time window in seconds 'routes' => [ // routes to apply rate limiting (wildcards allowed) 'home', 'api/*', 'admin/*', ], ], ];
If you want to limit all routes, you can use a '*' as route name.
Storages
As of the current release, this package exclusively supports Redis for backend storage.
return [ 'rate_limiting' => [ // ... other config options ... 'storage' => [ 'options' => [ 'host' => '127.0.0.1', 'port' => 6379 ], ], ], ];
Custom storage
If you want to provide your own storage implementation, make sure your class adheres to the Fet\LaminasRateLimiting\Storage\StorageInterface contract.
use Acme\Storage\DatabaseStorage; return [ 'rate_limiting' => [ // ... other config options ... 'storage' => [ 'name' => DatabaseStorage::class, // this will be loaded via service manager 'options' => [], ], ], ];
Tests
Run the tests with:
composer test
统计信息
- 总下载量: 767
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-11