PHPackages                             horde/stream - 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. horde/stream

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

horde/stream
============

PHP streams library

v2.0.0(1w ago)18.0k↑16.9%79LGPL-2.1-onlyPHPPHP ^8.1CI failing

Since Feb 12Pushed 3d ago6 watchersCompare

[ Source](https://github.com/horde/Stream)[ Packagist](https://packagist.org/packages/horde/stream)[ Docs](https://www.horde.org/libraries/Horde_Stream)[ RSS](/packages/horde-stream/feed)WikiDiscussions FRAMEWORK\_6\_0 Synced 2d ago

READMEChangelog (3)Dependencies (7)Versions (20)Used By (9)

Horde\\Stream
=============

[](#hordestream)

A managed stream abstraction for PHP that provides type guarantees, buffering strategies, lifecycle management and protocol-oriented read operations. Part of the [Horde](https://www.horde.org/) project.

Why not PSR-7 StreamInterface?
------------------------------

[](#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](doc/USAGE.md) for details and examples.

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

[](#installation)

```
composer require horde/stream
```

For the string-backed stream (`StringStream`), also install the stream wrapper:

```
composer require horde/stream_wrapper
```

Quick start
-----------

[](#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
----------------------

[](#stream-implementations)

ClassBackendUse case`Temp``php://temp`General-purpose buffering. Optional `maxMemory` parameter controls spill-to-disk threshold.`Existing`Caller-provided resourceWrap 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
-------------------

[](#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
-------------

[](#documentation)

- [doc/USAGE.md](doc/USAGE.md) - API reference, patterns and protocol examples.
- [doc/UPGRADING.md](doc/UPGRADING.md) - Migration guide from `Horde_Stream`(lib/) to `Horde\Stream` (src/).

Testing
-------

[](#testing)

```
# Unit tests (default suite)
phpunit

# Integration tests (requires horde/stream_wrapper)
phpunit --testsuite integration
```

License
-------

[](#license)

LGPL 2.1. See [LICENSE](LICENSE) for details.

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance99

Actively maintained with recent releases

Popularity30

Limited adoption so far

Community35

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~333 days

Total

14

Last Release

7d ago

Major Versions

1.6.3 → 2.0.0alpha12021-02-24

v1.7.1 → v2.0.0alpha42022-11-04

v1.7.2 → v2.0.0beta12026-04-08

PHP version history (7 changes)1.6.0PHP &gt;=5.3.0

1.6.2PHP &gt;=5.3.0,&lt;=6.0.0alpha1

1.6.3PHP &gt;=5.3.0,&lt;=8.0.0alpha1

2.0.0alpha1PHP ^7

v1.7.0PHP ^7.4 || ^8.0

v2.0.0alpha4PHP ^7.4 || ^8

v2.0.0RC1PHP ^8.1

### Community

Maintainers

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

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

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

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

![](https://www.gravatar.com/avatar/816e2b926f25f8cd2939054c7a7173011b4303d690e25ab61bf33cf8c7cf71ae?d=identicon)[tdannhauer](/maintainers/tdannhauer)

---

Top Contributors

[![yunosh](https://avatars.githubusercontent.com/u/379318?v=4)](https://github.com/yunosh "yunosh (70 commits)")[![slusarz](https://avatars.githubusercontent.com/u/381003?v=4)](https://github.com/slusarz "slusarz (66 commits)")[![ralflang](https://avatars.githubusercontent.com/u/646976?v=4)](https://github.com/ralflang "ralflang (23 commits)")[![mrubinsk](https://avatars.githubusercontent.com/u/66822?v=4)](https://github.com/mrubinsk "mrubinsk (13 commits)")[![ChristophWurst](https://avatars.githubusercontent.com/u/1374172?v=4)](https://github.com/ChristophWurst "ChristophWurst (2 commits)")[![thomasjfox](https://avatars.githubusercontent.com/u/1146758?v=4)](https://github.com/thomasjfox "thomasjfox (1 commits)")

---

Tags

Streamsbytestream

### Embed Badge

![Health badge](/badges/horde-stream/health.svg)

```
[![Health](https://phpackages.com/badges/horde-stream/health.svg)](https://phpackages.com/packages/horde-stream)
```

###  Alternatives

[horde/horde

Horde base application

583.0k71](/packages/horde-horde)[horde/kronolith

Calendar and scheduling application

101.5k5](/packages/horde-kronolith)

PHPackages © 2026

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