PHPackages                             tourze/workerman-anti-replay-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. [Security](/categories/security)
4. /
5. tourze/workerman-anti-replay-protocol

ActiveLibrary[Security](/categories/security)

tourze/workerman-anti-replay-protocol
=====================================

Workerman防重放攻击协议实现，提供数据包重放检测和防护功能

0.0.1(6mo ago)00MITPHPCI passing

Since Oct 31Pushed 4mo ago1 watchersCompare

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

READMEChangelog (1)Dependencies (9)Versions (2)Used By (0)

Workerman Anti-Replay Protocol
==============================

[](#workerman-anti-replay-protocol)

[![PHP Version Require](https://camo.githubusercontent.com/747d3c3ede1942feb8fd66c9176716ab12f766c93aa917e3d308d3c656450c01/68747470733a2f2f706f7365722e707567782e6f72672f746f75727a652f776f726b65726d616e2d616e74692d7265706c61792d70726f746f636f6c2f726571756972652f706870)](https://packagist.org/packages/tourze/workerman-anti-replay-protocol)[![Latest Stable Version](https://camo.githubusercontent.com/72433208f3e7d169616b89cb5b17c5ffb4cad93fabe4b5c290a07d4786d6de7a/68747470733a2f2f706f7365722e707567782e6f72672f746f75727a652f776f726b65726d616e2d616e74692d7265706c61792d70726f746f636f6c2f762f737461626c65)](https://packagist.org/packages/tourze/workerman-anti-replay-protocol)[![License](https://camo.githubusercontent.com/c57ff29224eddb89acac1d5bab99afbe830ab68147d828d181e2c812f7ce0b70/68747470733a2f2f706f7365722e707567782e6f72672f746f75727a652f776f726b65726d616e2d616e74692d7265706c61792d70726f746f636f6c2f6c6963656e7365)](https://packagist.org/packages/tourze/workerman-anti-replay-protocol)[![Total Downloads](https://camo.githubusercontent.com/2dab33586dadd1b7b5636247c5fe253ea5b5dad4d034ff6dacd12b5c1415ce16/68747470733a2f2f706f7365722e707567782e6f72672f746f75727a652f776f726b65726d616e2d616e74692d7265706c61792d70726f746f636f6c2f646f776e6c6f616473)](https://packagist.org/packages/tourze/workerman-anti-replay-protocol)[![Code Coverage](https://camo.githubusercontent.com/73ee3bab50824f778cedc6b4b3f78bcdab621eef812a979ec388b8ad692a4bff/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f2e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/tourze/php-monorepo)

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

这个包提供了一个防重放攻击的协议实现，适用于Workerman框架。

功能特点
----

[](#功能特点)

- 防止重放攻击
- 可配置的检查长度
- 可配置的TTL (生存时间)
- 与Workerman框架集成
- 支持PSR日志

安装
--

[](#安装)

```
composer require tourze/workerman-anti-replay-protocol
```

使用方法
----

[](#使用方法)

```
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Psr\Log\LoggerInterface;
use Tourze\Workerman\AntiReplayProtocol\AntiReplay;
use Tourze\Workerman\AntiReplayProtocol\Config;

// 创建配置
$config = new Config();
$config->setCache(new FilesystemAdapter());
$config->setLogger($logger); // 实现了LoggerInterface的日志对象
$config->setCheckLength(32); // 可选，默认为32
$config->setTtl(60 * 60 * 24); // 可选，默认为24小时

// 设置防重放协议配置
AntiReplay::setConfig($config);

// 在Workerman中使用
$worker = new Worker('AntiReplay://0.0.0.0:8080');
$worker->onMessage = function($connection, $data) {
    // 处理数据
};
```

协议工作原理
------

[](#协议工作原理)

防重放协议通过检查数据包的前N个字节来检测重放攻击。如果检测到相同的数据包头部，连接将被拒绝。

配置选项
----

[](#配置选项)

- `checkLength`: 要检查的头字节长度，默认为32
- `cache`: 用于存储已处理请求哈希的缓存适配器
- `ttl`: 缓存的生存时间，默认为24小时
- `logger`: 用于记录重放攻击尝试的PSR兼容日志记录器

开发
--

[](#开发)

### 安装依赖

[](#安装依赖)

```
composer install
```

### 运行测试

[](#运行测试)

```
./vendor/bin/phpunit tests
```

参考文档
----

[](#参考文档)

- [shadowsocks防重放攻击](https://github.com/shadowsocks/shadowsocks-org/issues/184)
- [Workerman文档](https://www.workerman.net/doc)

License
-------

[](#license)

本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance71

Regular maintenance activity

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

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

Unknown

Total

1

Last Release

193d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-workerman-anti-replay-protocol/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-workerman-anti-replay-protocol/health.svg)](https://phpackages.com/packages/tourze-workerman-anti-replay-protocol)
```

###  Alternatives

[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k348.9M2.5k](/packages/symfony-cache)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.4k37.3k](/packages/matomo-matomo)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

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