PHPackages                             skyjerry/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. skyjerry/rate-limiter

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

skyjerry/rate-limiter
=====================

A rate limiter library for PHP

0.0.2(2y ago)04MITPHPPHP &gt;=8.0

Since Mar 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/skyjerry/rate-limiter)[ Packagist](https://packagist.org/packages/skyjerry/rate-limiter)[ RSS](/packages/skyjerry-rate-limiter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

rate-limiter
============

[](#rate-limiter)

[English](#english-version) | [中文](#%E4%B8%AD%E6%96%87%E7%89%88)

中文版
---

[](#中文版)

这是一个简单的 PHP 限流器类库,提供了令牌桶和滑动窗口两种限流算法,以及文件存储和 Redis 存储两种存储方式。

### 功能特性

[](#功能特性)

- 支持令牌桶和滑动窗口两种限流算法，并支持扩展
- 支持文件存储和 Redis 存储两种存储方式，并支持扩展
- 限流规则可以针对全局或特定的资源 key
- 提供了 PSR-4 标准的自动加载机制
- 包含单元测试,保证代码质量

### 使用方法

[](#使用方法)

1. 通过 Composer 安装: ```
    composer require skyjerry/rate-limiter
    ```
2. 在代码中使用: ```
    $storageConfig = [
        'filePath' => sys_get_temp_dir() . '/test_rate_limiter.data',
    ];
    $rateLimiter = \RateLimiter\RateLimiterFactory::createRateLimiter(
         'tokenBucket',
         'file',
         $storageConfig,
         10,
         1
    );

    if (!$rateLimiter->acquire('user_1', 10)) {
        echo "限流了!";
    }
    ```

### 注意事项

[](#注意事项)

- 这是一个 Demo 级别的项目,仅供学习参考,不建议用于生产环境。
- 在高并发场景下,建议使用 Redis 等内存型存储,以提高性能。
- 限流规则的设置需要根据实际业务需求进行调整,不同的场景可能需要不同的限流策略。

### 贡献指南

[](#贡献指南)

欢迎提交 Issue 和 Pull Request,帮助改进这个项目。在提交 PR 之前,请先运行单元测试,确保所有测试都能通过。

### English Version

[](#english-version)

This is a simple rate limiter library for PHP, providing two rate limiting algorithms: token bucket and sliding window, and two storage methods: file storage and Redis storage.

### Features

[](#features)

- Supports two rate limiting algorithms: token bucket and sliding window
- Supports two storage methods: file storage and Redis storage
- Rate limiting rules can be applied globally or to specific resource keys
- Provides PSR-4 standard autoloading mechanism
- Includes unit tests to ensure code quality

### Usage

[](#usage)

1. Install via Composer: ```
    composer require skyjerry/rate-limiter
    ```
2. Use in your code: ```
    $storageConfig = [
        'filePath' => sys_get_temp_dir() . '/test_rate_limiter.data',
    ];
    $rateLimiter = \RateLimiter\RateLimiterFactory::createRateLimiter(
         'tokenBucket',
         'file',
         $storageConfig,
         10,
         1
    );

    if (!$rateLimiter->acquire('user_1', 10)) {
        echo "Rate limited!";
    }
    ```

### Cautions

[](#cautions)

- This is a demo-level project, for learning reference only, not recommended for direct use in production environments.
- For high concurrency scenarios, it is recommended to use memory-based storage like Redis to improve performance.
- The setting of rate limiting rules needs to be adjusted according to actual business requirements, different scenarios may require different rate limiting strategies.

### Contribution Guide

[](#contribution-guide)

Issues and Pull Requests are welcome to help improve this project. Before submitting a PR, please run the unit tests to ensure all tests pass.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

784d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7d9a4a8c56cb2c38b6377edec77742fec2d31f24ba4973eeffb83e3e0579fe31?d=identicon)[skyjerry](/maintainers/skyjerry)

---

Top Contributors

[![skyjerry](https://avatars.githubusercontent.com/u/16223787?v=4)](https://github.com/skyjerry "skyjerry (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[oveleon/contao-component-style-manager

Style and CSS-Class Manager for Contao Open Source CMS

2535.8k6](/packages/oveleon-contao-component-style-manager)[coldtrick/thewire_tools

Extend the functionality of The Wire

133.2k](/packages/coldtrick-thewire-tools)

PHPackages © 2026

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