PHPackages                             tourze/workerman-rate-limit-protocol - 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. tourze/workerman-rate-limit-protocol

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

tourze/workerman-rate-limit-protocol
====================================

Workerman Rate Limit Protocol

0.0.2(6mo ago)01MITPHPCI passing

Since Apr 4Pushed 5mo ago1 watchersCompare

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

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

Workerman Rate Limit Protocol
=============================

[](#workerman-rate-limit-protocol)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/a1b34b4f0a868887b55d717437cf06c75063c73e9d201b9dc18bfbb05ed68275/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f776f726b65726d616e2d726174652d6c696d69742d70726f746f636f6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/workerman-rate-limit-protocol)[![Total Downloads](https://camo.githubusercontent.com/c965e9e428c41d089f733f0a241f72de41d514ed1fef701b16b4140995ce118a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f776f726b65726d616e2d726174652d6c696d69742d70726f746f636f6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/workerman-rate-limit-protocol)[![PHP Version](https://camo.githubusercontent.com/803e00120e11b5ca51373ffa8494b30b28e326a92d9f0d8a063b034315c8d4df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f776f726b65726d616e2d726174652d6c696d69742d70726f746f636f6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/workerman-rate-limit-protocol)[![License](https://camo.githubusercontent.com/4aafb6bdbf2b93e4f13fc2f06a0f96c85d199cc292bc6710f1dbd7b0d8f03531/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f776f726b65726d616e2d726174652d6c696d69742d70726f746f636f6c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/tourze/workerman-rate-limit-protocol/blob/master/LICENSE)

A rate limiting protocol implementation integrated with Workerman.

Features
--------

[](#features)

- Provides traffic-based rate limiting protocol (bytes/second).
- Provides packet-based rate limiting protocol (packets/second).
- Supports setting default rate limits globally and overriding limits for specific connections.
- Non-intrusive usage, acts as a wrapper around existing Workerman protocols (defaults to raw TCP/UDP handling if no inner protocol specified).
- Uses `WeakMap` to store connection context for automatic memory management (no manual cleanup needed on connection close).
- **TCP Connections**: Pauses receiving data (`pauseRecv`) instead of closing when the rate limit is exceeded. Resumes automatically after 1 second.
- **UDP Connections**: Directly discards packets when the rate limit is exceeded.
- **Important Note**: Rate limiting is currently implemented **per-process**. In a multi-process Workerman setup, the limit applies independently to each worker process, not globally across all processes.

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

[](#installation)

```
composer require tourze/workerman-rate-limit-protocol
```

Quick Start
-----------

[](#quick-start)

### Traffic-based Rate Limiting (Bytes/Second)

[](#traffic-based-rate-limiting-bytessecond)

```
