perimeter/rate-limiter-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

perimeter/rate-limiter-php

最新稳定版本:v0.1.1

Composer 安装命令:

composer require perimeter/rate-limiter-php

包简介

A very simple Rate Limiter for PHP

README 文档

README

Build Status

Rate Limit those APIs!

Installation

$ composer.phar require perimeter/rate-limiter-php:dev-develop

This library can be used alongside the perimeter/RateLimitBundle for Symfony2 applications. See the repository for more instructions.

Get Started

Create your throttler:

include_once('vendor/autoload.php');

$redis = new Predis\Client();
$throttler = new Perimeter\RateLimiter\Throttler\RedisThrottler($redis);

Ensure redis is running by executing the redis-server command on the web server where the library is running:

$ redis-server

Now you can throttle your users accordingly!

// Create a meter ID based on something unique to your user
// In this case we use the IP. This can also be a username,
// company, or some other authenticated property
$meterId = sprintf('ip_address:%s', $_SERVER['REMOTE_ADDR']);
$warnThreshold = 10;
$limitThreshold = 20;

// run the "consume" command
$throttler->consume($meterId, $warnThreshold, $limitThreshold);

if ($throttler->isLimitWarning()) {
    echo "slow down!";
}

if ($throttler->isLimitExceeded()) {
    exit("you have been rate limited");
}

And that's it!

统计信息

  • 总下载量: 15.27k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-26