PHPackages                             friendsofhyperf/rate-limit - 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. friendsofhyperf/rate-limit

ActiveLibrary

friendsofhyperf/rate-limit
==========================

Rate limiting component for Hyperf with support for multiple algorithms (Fixed Window, Sliding Window, Token Bucket, Leaky Bucket).

v3.1.75(5mo ago)0390MITPHP

Since Nov 18Pushed 5mo agoCompare

[ Source](https://github.com/friendsofhyperf/rate-limit)[ Packagist](https://packagist.org/packages/friendsofhyperf/rate-limit)[ Fund](https://hdj.me/sponsors/)[ GitHub Sponsors](https://github.com/huangdijia)[ RSS](/packages/friendsofhyperf-rate-limit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (7)Versions (11)Used By (0)

Rate Limit
==========

[](#rate-limit)

[![Latest Stable Version](https://camo.githubusercontent.com/d6b166b64613c77a1c55a8390f4a1d595a8d49df7ee701042039c59e24f819a5/68747470733a2f2f706f7365722e707567782e6f72672f667269656e64736f666879706572662f726174652d6c696d69742f76)](https://packagist.org/packages/friendsofhyperf/rate-limit)[![Total Downloads](https://camo.githubusercontent.com/2548eb8180470625190ef310c84614f00a929ea156973b63b935bf8618a0dd0d/68747470733a2f2f706f7365722e707567782e6f72672f667269656e64736f666879706572662f726174652d6c696d69742f646f776e6c6f616473)](https://packagist.org/packages/friendsofhyperf/rate-limit)[![License](https://camo.githubusercontent.com/5f77ec355573a55b272beba6ce63f398059f49dcd6ce2594f4dec83e8595bcf4/68747470733a2f2f706f7365722e707567782e6f72672f667269656e64736f666879706572662f726174652d6c696d69742f6c6963656e7365)](https://packagist.org/packages/friendsofhyperf/rate-limit)

Rate limiting component for Hyperf with support for multiple algorithms (Fixed Window, Sliding Window, Token Bucket, Leaky Bucket).

Installation
------------

[](#installation)

```
composer require friendsofhyperf/rate-limit
```

Requirements
------------

[](#requirements)

- Hyperf ~3.1.0
- Redis

Features
--------

[](#features)

- **Multiple Rate Limiting Algorithms**
    - Fixed Window
    - Sliding Window
    - Token Bucket
    - Leaky Bucket
- **Flexible Usage**
    - Annotation-based rate limiting via Aspect
    - Custom middleware support
- **Smart Order for Multiple Annotations**
    - Automatic prioritization of multiple RateLimit annotations
    - Intelligent ordering by strictness (maxAttempts/decay ratio)
    - More restrictive limits evaluated first for better performance
- **Flexible Key Generation**
    - Default method/class-based keys
    - Custom key with placeholders support
    - Array keys support
    - Callable keys support
- **Customizable Responses**
    - Custom response message
    - Custom HTTP response code
- **Multi Redis Pool Support**

Usage
-----

[](#usage)

### Method 1: Using Annotation

[](#method-1-using-annotation)

The easiest way to add rate limiting is using the `#[RateLimit]` attribute:

```
