Download the PHP package tinywan/limit-traffic without Composer

On this page you can find all versions of the php package tinywan/limit-traffic. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package limit-traffic

based on lua script limiting traffic for webman plugin

Latest Stable Version Total Downloads Latest Unstable Version License

为防止滥用,你应该考虑对您的 API 限流。 例如,您可以限制每个用户 10 分钟内最多调用 API 100 次。 如果在规定的时间内接收了一个用户大量的请求,将返回响应状态代码 429 (这意味着过多的请求)。

安装

使用

应用中间件

config/middleware.php 中添加全局中间件如下:

路由中间件

注意:需要 workerman/webman-framework 版本 >= 1.0.12

我们可以给某个一个或某一组路由设置中间件。例如在 config/route.php 中添加如下配置:

🔏 返回允许的请求的最大数目及时间

返回允许的请求的最大数目及时间,例如:[100, 600] 表示在 600 秒内最多 100 次的 API 调

⚠ 请求限制参考

🔰 响应参数详解

自定义自己的 Response

使用场景

  • 每个项目有标准的统一输出,自定义返回内容
  • 前后端分离:前端要求返回的 HTTP状态码并不是 429,而是 200 或者其他
  • 响应的body不是 {"code":0,"msg":"Too Many Requests"},而是 {"error_code":200,"message":"Too Many Requests"}等其他内容

自定义HTTP状态码

编辑 config/plugin/tinywan/limit-traffic/app.php 文件的 status HTTP 状态码(默认值是 429

自定义body返回内容

编辑 config/plugin/tinywan/limit-traffic/app.php 文件的 body 的字段

默认选项是

自定义选项参考一

1、假设status HTTP 状态码设置为 200

2、假设body的数组设为为

则响应内容为

其他的可以根据自身业务自定义即可

Other


All versions of limit-traffic with dependencies

PHP Build Version
Package Version
Requires ext-redis Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tinywan/limit-traffic contains the following files

Loading the files please wait ....