PHPackages                             tourze/quic-flow-control - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. tourze/quic-flow-control

ActiveLibrary[HTTP &amp; Networking](/categories/http)

tourze/quic-flow-control
========================

QUIC协议流量控制实现，提供连接级和流级流量控制机制

0.1.0(6mo ago)0311MITPHPCI passing

Since Jun 3Pushed 6mo agoCompare

[ Source](https://github.com/tourze/quic-flow-control)[ Packagist](https://packagist.org/packages/tourze/quic-flow-control)[ RSS](/packages/tourze-quic-flow-control/feed)WikiDiscussions master Synced 1mo ago

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

QUIC Flow Control
=================

[](#quic-flow-control)

[![PHP Version Require](https://camo.githubusercontent.com/acffb6ae1962992d26e4466782832787e79504a6250f80d732c4283458b9f497/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c75652e737667)](https://packagist.org/packages/tourze/quic-flow-control)[![License](https://camo.githubusercontent.com/c7a55d915671a5aed9ace0e19b5b73adddff6e83043235f7dca0f00939c7e109/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f746f75727a652f717569632d666c6f772d636f6e74726f6c2e737667)](https://github.com/tourze/quic-flow-control/blob/main/LICENSE)[![Build Status](https://camo.githubusercontent.com/34e9f94ddfe49581eb03760f1506680fb927eee623fa94711027a8345d4bba3a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f7068702d6d6f6e6f7265706f2f63692e796d6c3f6272616e63683d6d61696e)](https://github.com/tourze/php-monorepo/actions)[![Code Coverage](https://camo.githubusercontent.com/9cb168340a6d5a1bdda8e16dafe8eed3d60f1441986fb63de17bff84ee6a18f0/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f)](https://codecov.io/gh/tourze/php-monorepo)

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

QUIC协议流量控制实现，提供连接级和流级流量控制机制，完全符合RFC 9000规范。

目录
--

[](#目录)

- [功能特性](#%E5%8A%9F%E8%83%BD%E7%89%B9%E6%80%A7)
- [安装](#%E5%AE%89%E8%A3%85)
- [Dependencies](#dependencies)
- [Quick Start](#quick-start)
- [运行演示](#%E8%BF%90%E8%A1%8C%E6%BC%94%E7%A4%BA)
- [Advanced Usage](#advanced-usage)
- [测试](#%E6%B5%8B%E8%AF%95)
- [RFC 9000 合规性](#rfc-9000-%E5%90%88%E8%A7%84%E6%80%A7)
- [许可证](#%E8%AE%B8%E5%8F%AF%E8%AF%81)

功能特性
----

[](#功能特性)

### 核心组件

[](#核心组件)

- **FlowControlWindow** - 流量控制窗口管理
- **StreamFlowController** - 流级流量控制器
- **ConnectionFlowController** - 连接级流量控制器
- **FlowControlManager** - 统一流量控制管理器

### 流控制帧支持

[](#流控制帧支持)

- **MAX\_DATA** - 连接级窗口更新帧
- **MAX\_STREAM\_DATA** - 流级窗口更新帧
- **DATA\_BLOCKED** - 连接级阻塞信号帧
- **STREAM\_DATA\_BLOCKED** - 流级阻塞信号帧

### 主要功能

[](#主要功能)

- ✅ 连接级和流级双重流量控制
- ✅ 自动阻塞检测和信号生成
- ✅ 智能窗口更新机制
- ✅ 完整的统计和健康监控
- ✅ RFC 9000完全兼容

安装
--

[](#安装)

```
composer require tourze/quic-flow-control
```

Dependencies
------------

[](#dependencies)

本包依赖以下组件：

### 运行时依赖

[](#运行时依赖)

- **tourze/quic-core** - QUIC 协议核心组件，提供常量和基础类型定义
- **tourze/quic-frames** - QUIC 帧实现，提供流控制帧的结构定义

### 开发依赖

[](#开发依赖)

- **phpstan/phpstan** ^2.1 - 静态分析工具
- **phpunit/phpunit** ^10.0 - 单元测试框架

### 系统要求

[](#系统要求)

- PHP 8.1 或更高版本
- 内存：建议 64MB 以上
- 支持的操作系统：Linux, macOS, Windows

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

[](#quick-start)

```
use Tourze\QUIC\FlowControl\FlowControlManager;

// 创建流量控制管理器
$manager = new FlowControlManager(
    1048576,  // 连接级最大数据量 (1MB)
    1048576,  // 本地连接级最大数据量
    65536,    // 流级最大数据量 (64KB)
    65536     // 本地流级最大数据量
);

// 创建流
$stream = $manager->createStream(1);

// 发送数据
$success = $manager->sendData(1, 1024);
if (!$success) {
    echo "发送失败，窗口不足\n";
}

// 接收数据
$manager->receiveData(1, 512);

// 检查健康状态
$health = $manager->getHealthStatus();
echo "健康状态: " . $health['status'] . "\n";

// 获取待发送的控制帧
$frames = $manager->getPendingFrames();
foreach ($frames as $frame) {
    echo "待发送: " . $frame['type'] . "\n";
}
```

运行演示
----

[](#运行演示)

```
cd packages/quic-flow-control
php examples/demo.php
```

演示脚本展示了完整的流量控制流程，包括：

- 窗口管理
- 阻塞检测
- 控制帧生成
- 健康监控

Advanced Usage
--------------

[](#advanced-usage)

### 自定义流量控制配置

[](#自定义流量控制配置)

```
use Tourze\QUIC\FlowControl\FlowControlManager;
use Tourze\QUIC\Core\Constants;

// 创建高性能配置的流量控制管理器
$manager = new FlowControlManager(
    16 * 1024 * 1024,  // 16MB 连接窗口 - 适合高带宽场景
    16 * 1024 * 1024,  // 16MB 本地连接窗口
    1024 * 1024,       // 1MB 流窗口 - 适合大文件传输
    1024 * 1024        // 1MB 本地流窗口
);
```

### 流量控制监控和诊断

[](#流量控制监控和诊断)

```
// 获取详细统计信息
$stats = $manager->getFullStats();

// 连接级统计
$connectionStats = $stats['connection'];
echo "连接窗口利用率: " . ($connectionStats['send_window']['utilization'] * 100) . "%\n";
echo "已发送字节: " . $connectionStats['send_window']['bytes_sent'] . "\n";
echo "窗口大小: " . $connectionStats['send_window']['window_size'] . "\n";

// 流级统计
foreach ($stats['streams'] as $streamId => $streamStats) {
    echo "流 {$streamId} 状态: " . ($streamStats['blocked'] ? '阻塞' : '正常') . "\n";
    echo "流 {$streamId} 利用率: " . ($streamStats['send_window']['utilization'] * 100) . "%\n";
}

// 健康状态监控
$health = $stats['health'];
if ($health['status'] !== 'healthy') {
    echo "警告: 流量控制状态异常 - " . $health['status'] . "\n";
    foreach ($health['warnings'] as $warning) {
        echo "- " . $warning . "\n";
    }
}
```

### 流控制帧处理

[](#流控制帧处理)

```
// 处理接收到的流控制帧
foreach ($receivedFrames as $frame) {
    switch ($frame['type']) {
        case 'MAX_DATA':
            $manager->handleMaxDataFrame($frame['max_data']);
            break;

        case 'MAX_STREAM_DATA':
            $manager->handleMaxStreamDataFrame(
                $frame['stream_id'],
                $frame['max_stream_data']
            );
            break;

        case 'DATA_BLOCKED':
            $manager->handleDataBlockedFrame($frame['data_limit']);
            break;

        case 'STREAM_DATA_BLOCKED':
            $manager->handleStreamDataBlockedFrame(
                $frame['stream_id'],
                $frame['stream_data_limit']
            );
            break;
    }
}

// 获取需要发送的控制帧
$pendingFrames = $manager->getPendingFrames();
foreach ($pendingFrames as $frame) {
    // 发送到网络层
    sendToNetwork($frame);
}
```

### 性能优化建议

[](#性能优化建议)

```
// 1. 批量操作多个流
$streamIds = [1, 3, 5, 7, 9];
foreach ($streamIds as $streamId) {
    if ($manager->canSendData($streamId, 1024)) {
        $manager->sendData($streamId, 1024);
    }
}

// 2. 定期检查健康状态
$healthCheckInterval = 30; // 30秒
if (time() % $healthCheckInterval === 0) {
    $health = $manager->getHealthStatus();
    if ($health['status'] !== 'healthy') {
        // 记录警告或采取纠正措施
        logWarning('Flow control health issue', $health);
    }
}

// 3. 动态调整窗口大小（根据网络条件）
$connectionStats = $manager->getConnectionController()->getConnectionStats();
$utilization = $connectionStats['connection']['send_window']['utilization'];

if ($utilization > 0.8) {
    // 高利用率 - 考虑请求更大窗口
    echo "建议请求更大的连接窗口\n";
}
```

### 错误处理和恢复

[](#错误处理和恢复)

```
use Tourze\QUIC\FlowControl\Exception\FlowControlException;
use Tourze\QUIC\FlowControl\Exception\InvalidFlowControlWindowException;

try {
    $success = $manager->sendData($streamId, $dataSize);
    if (!$success) {
        // 发送失败，检查原因
        if ($manager->isConnectionBlocked()) {
            echo "连接级流量控制阻塞\n";
        } elseif ($manager->isStreamBlocked($streamId)) {
            echo "流级流量控制阻塞\n";
        }
    }
} catch (FlowControlException $e) {
    echo "流量控制错误: " . $e->getMessage() . "\n";

    // 重置流量控制状态（极端情况）
    $manager->reset();
} catch (InvalidFlowControlWindowException $e) {
    echo "无效的流量控制窗口: " . $e->getMessage() . "\n";
}
```

测试
--

[](#测试)

运行单元测试：

```
./vendor/bin/phpunit packages/quic-flow-control/tests/
```

测试覆盖：

- ✅ 42个测试用例
- ✅ 115个断言
- ✅ 100%通过率

RFC 9000 合规性
------------

[](#rfc-9000-合规性)

本实现严格遵循QUIC RFC 9000第4节流量控制规范：

- 连接级流量控制 (Section 4.1)
- 流级流量控制 (Section 4.1)
- 流控制帧格式 (Section 19.9-19.13)
- 阻塞信号机制
- 窗口更新策略

许可证
---

[](#许可证)

MIT License

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance72

Regular maintenance activity

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity27

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 ~149 days

Total

2

Last Release

190d 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)")

---

Tags

protocolnetworkquicflow-control

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-quic-flow-control/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-quic-flow-control/health.svg)](https://phpackages.com/packages/tourze-quic-flow-control)
```

PHPackages © 2026

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