承接 horde/stream 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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\n or 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 another StreamInterface, copying data efficiently in chunks.
  • Automatic memory management - TempString starts in a pure-PHP string backend and transparently spills to php://temp when 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/) to Horde\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.

统计信息

  • 总下载量: 7.57k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 10
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 6
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-2.1-only
  • 更新时间: 2023-10-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固