mabe / ratelimit-bundle
此symfony扩展包提供了基于Redis限制请求的功能。
v0.1.1
2018-10-19 02:46 UTC
Requires
- php: ^7.1
- symfony/framework-bundle: ^3.0|^4.0
Requires (Dev)
- symfony/browser-kit: ^4.1
- symfony/http-kernel: ^4.1
- symfony/phpunit-bridge: ^4.1
- symfony/security-bundle: ^2.7|^3.0|^4.0
- symfony/yaml: ^4.1
This package is auto-updated.
Last update: 2024-09-13 18:37:29 UTC
README
RateLimitBundle
一个轻量级的symfony扩展包,用于限制指定路径的请求速率。
要求
Redis服务器
安装
步骤 1: 下载扩展包
打开命令行控制台,进入您的项目目录,并执行以下命令以下载此扩展包的最新稳定版本
$ composer require mabe/ratelimit-bundle
此命令要求您全局安装了Composer,具体请参考Composer文档中的安装章节。
步骤 2: 启用扩展包
然后,通过将其添加到项目app/AppKernel.php
文件中已注册的扩展包列表中来启用扩展包
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Mabe\RateLimitBundle\MabeRateLimitBundle(), ); // ... } // ... }
步骤 3: 配置
在config.yml中添加您想要的配置。
rate_limit: enabled: true redis: # Your redis server IP (default localhost) and database host: 127.0.0.1 database: 5 paths: # Path to put restriction on - path: /api/test # Times the path can be accessed limit: 1 # Period in seconds period: 5 # Redis identifier for storing keys (ip or username currently available) identifier: ip
运行测试
./vendor/bin/simple-phpunit