PHPackages                             kkong/rate-limiter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kkong/rate-limiter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kkong/rate-limiter
==================

a demo rate-limiter

01PHP

Since May 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/adgad2/RateLimterDemo)[ Packagist](https://packagist.org/packages/kkong/rate-limiter)[ RSS](/packages/kkong-rate-limiter/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

使用方法
----

[](#使用方法)

composer安装

```
composer require kkong/rate-limiter

```

将源码下载放置到代码目录，然后在需要使用的代码里引用，或在入口文件里引用

```
require 'RateLimiter/vendor/Autoloader.php';

```

是什么？
----

[](#是什么)

一个简单的限流器demo

节流策略
----

[](#节流策略)

目前有3种节流方式,TimeWindow、SlidingTimeWindow和TokenBucket

```
$client = new \Predis\Client([
    'host'   => '127.0.0.1',
    'port'   => 6379,
]);
//定义实现了StorageInterface的示例
$storage = new \Kkong\RateLimiter\Storage\Redis($client);

/**
 * 自然天，每天限制1000次
 */
$timeWindow = new \Kkong\RateLimiter\Strategy\TimeWindowStrategy($storage);
$timeWindow->attempt('key', 1000, 86400000);

/**
 * 每10秒限制100次
 */
$slidingWindow = new \Kkong\RateLimiter\Strategy\SlidingWindowStrategy($storage);
$slidingWindow->attempt('key', 1000, 10);

/**
 * 总令牌容量1000，每秒补充10个令牌
 */
$tokenBucket = new \Kkong\RateLimiter\Strategy\TokenBucketStrategy($storage);
$tokenBucket->attempt('key', 1000, 10);
```

存储引擎
----

[](#存储引擎)

暂时只提供1个储存引擎,如果需要继续扩展，需要继承StorageInterface并实现相应的方法

- Redis

###  Health Score

12

—

LowBetter than 0% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17292685?v=4)[zhu](/maintainers/adgad2)[@adgad2](https://github.com/adgad2)

### Embed Badge

![Health badge](/badges/kkong-rate-limiter/health.svg)

```
[![Health](https://phpackages.com/badges/kkong-rate-limiter/health.svg)](https://phpackages.com/packages/kkong-rate-limiter)
```

###  Alternatives

[roots/wp-config

Fluent configuration management for WordPress

638.3M83](/packages/roots-wp-config)[fanmade/laravel-bitwise-trait

Simple trait to use bitwise operators on any class

1376.5k](/packages/fanmade-laravel-bitwise-trait)[voodoophp/paginator

Paginator is a simple class that allows you to create pagination. It doesn't require any database connection. It is compatible with Twitter's Bootstrap Framework, by using the CSS class pagination that is also attached.

351.5k1](/packages/voodoophp-paginator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
