horde/stream
Composer 安装命令:
composer require horde/stream
包简介
PHP streams library
关键字:
README 文档
README
A managed stream abstraction for PHP that provides type guarantees, buffering strategies, lifecycle management and protocol-oriented read operations. Part of the Horde project.
Why not PSR-7 StreamInterface?
PSR-7 streams (Psr\Http\Message\StreamInterface) model HTTP message bodies:
a thin wrapper around a PHP resource with read(), write() and seek().
They are the right tool for HTTP request/response transport.
Horde\Stream targets a different problem space: parsing and constructing structured data over byte streams, the kind of work that IMAP, SMTP, MIME, and ManageSieve libraries do on every connection. This requires operations that PSR-7 does not offer:
- Delimiter scanning - read until
},\r\nor any multi-byte delimiter without buffering the entire stream into a string first. - Positional search - find the byte offset of a substring, forward or reverse, without consuming data.
- Peek without consume - inspect upcoming bytes and rewind automatically.
- UTF-8 character-level seeking and reading - navigate by character count rather than byte count for multibyte-safe protocol handling.
- EOL auto-detection - determine whether a stream uses LF or CRLF line endings.
- Polymorphic write -
add()accepts a string, a PHP resource or anotherStreamInterface, copying data efficiently in chunks. - Automatic memory management -
TempStringstarts in a pure-PHP string backend and transparently spills tophp://tempwhen size exceeds a configurable threshold. - Safe cloning and serialization - clone a stream to get an independent copy; serialize to persist both data and cursor position.
A future PSR-7 adapter layer can bridge the two worlds when HTTP interop is needed. See doc/USAGE.md for details and examples.
Installation
composer require horde/stream
For the string-backed stream (StringStream), also install the stream wrapper:
composer require horde/stream_wrapper
Quick start
use Horde\Stream\Temp; $stream = new Temp(); $stream->add("From: alice@example.com\r\nSubject: Hello\r\n\r\nBody text."); $stream->rewind(); // Read header lines while (!$stream->eof()) { $line = $stream->getToChar("\r\n", all: false); if ($line === '') { break; // blank line = end of headers } echo $line, "\n"; } // Read remaining body echo $stream->substring(), "\n";
Stream implementations
| Class | Backend | Use case |
|---|---|---|
Temp |
php://temp |
General-purpose buffering. Optional maxMemory parameter controls spill-to-disk threshold. |
Existing |
Caller-provided resource | Wrap a socket, file handle or any open PHP stream resource. |
StringStream |
horde/stream_wrapper |
String-backed stream with full seek support. Requires horde/stream_wrapper. |
TempString |
String, spills to php://temp |
Starts in fast string backend, transparently switches to temp stream when data exceeds maxMemory. |
Interface hierarchy
Readable Writable Seekable Stringable
\ | / /
\ | / /
StreamInterface ----------------
|
AbstractStream
/ | \ \
Temp Existing StringStream TempString
StreamInterface composes Readable, Writable, Seekable and
Stringable. Consumer code can type-hint on the narrow interface when only
a subset of capabilities is needed.
Documentation
- doc/USAGE.md - API reference, patterns and protocol examples.
- doc/UPGRADING.md - Migration guide from
Horde_Stream(lib/) toHorde\Stream(src/).
Testing
# Unit tests (default suite) phpunit # Integration tests (requires horde/stream_wrapper) phpunit --testsuite integration
License
LGPL 2.1. See LICENSE for details.
horde/stream 适用场景与选型建议
horde/stream 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.82k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Streams」 「bytestream」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 horde/stream 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 horde/stream 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 horde/stream 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Pop Http Component for Pop PHP Framework
A simple, type-safe, zero dependency port of the javascript fetch WebApi for PHP
Manage portfolio projects and clients
Light weight API performing single/multiple shell command execution using IO multiplexing
A WYSIWYG editor field type powered by RedactorJS.
Painless stream filtering in PHP.
统计信息
- 总下载量: 7.82k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: LGPL-2.1-only
- 更新时间: 2023-10-26