PHPackages                             sandromiguel/php-streams - 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. sandromiguel/php-streams

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

sandromiguel/php-streams
========================

A PHP library for stream handling following PSR-7 standards.

v1.2.0(2y ago)77MITPHPPHP &gt;=8.1

Since Mar 12Pushed 2y ago2 watchersCompare

[ Source](https://github.com/SandroMiguel/php-streams)[ Packagist](https://packagist.org/packages/sandromiguel/php-streams)[ Docs](https://github.com/SandroMiguel/php-sceleto)[ RSS](/packages/sandromiguel-php-streams/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (10)Versions (10)Used By (0)

PhpStreams
==========

[](#phpstreams)

[![License](https://camo.githubusercontent.com/3a82d1dcad27d57a3b231dc6c204d0ce471273d5fe8c652c3993887408d63fb3/68747470733a2f2f706f7365722e707567782e6f72672f73616e64726f6d696775656c2f7068702d73747265616d732f6c6963656e7365)](//packagist.org/packages/sandromiguel/verum-php)[![Latest Stable Version](https://camo.githubusercontent.com/cb9b4dcde117522510fa38138fe4f16f3d59e3321fee8571abd005f0a3e1561a/68747470733a2f2f706f7365722e707567782e6f72672f73616e64726f6d696775656c2f7068702d73747265616d732f76)](//packagist.org/packages/sandromiguel/verum-php)[![Dependents](https://camo.githubusercontent.com/b7302b0450107ef18e58dc6893e438e20e81ddd40abcceebdca25f807ca362cb/68747470733a2f2f706f7365722e707567782e6f72672f73616e64726f6d696775656c2f7068702d73747265616d732f646570656e64656e7473)](//packagist.org/packages/sandromiguel/verum-php)

PhpStreams is a PHP library that provides stream handling following the PSR-7 standards.

Features
--------

[](#features)

- **Stream Manipulation**: Read from and write to streams with ease.
- **PSR-7 Compatibility**: Conforms to the [PSR-7](https://www.php-fig.org/psr/psr-7/) standards for interoperability.
- **Flexible**: Offers a comprehensive set of features for stream manipulation.

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

[](#installation)

You can install PhpStreams via Composer:

```
composer require sandromiguel/php-streams
```

Usage
-----

[](#usage)

#### Try it on replit.com

[](#try-it-on-replitcom)

Try out the interactive examples on the replit.com platform:

[Run on replit.com](https://replit.com/@SandroMiguel/PhpStreams)

### Text Stream in Memory

[](#text-stream-in-memory)

```
require 'vendor/autoload.php';

use PhpStreams\Stream;

// Create a text stream in memory
$stream = new Stream(fopen('php://temp', 'r+'));

// Write data to the stream
$stream->write("Hello, world!\n");

// Move the pointer to the beginning of the stream
$stream->rewind();

// Read data from the stream
$data = $stream->getContents();

echo $data;
```

Output example

```
Hello, world!

```

### Reading from a File

[](#reading-from-a-file)

```
require 'vendor/autoload.php';

use PhpStreams\Stream;

// Open a file for reading
$fileHandle = fopen('example.txt', 'r');

// Create a stream from the file handle
$fileStream = new Stream($fileHandle);

// Check if the stream is readable
$fileContents = $fileStream->isReadable() ? $fileStream->getContents() : null;

if ($fileContents) {
  echo $fileContents;
} else {
  echo "The file is not readable.";
}

// Close the file handle
fclose($fileHandle);
```

Output example (if example.txt contains "Hello, my name is example.txt"):

```
Hello, my name is example.txt

```

### Writing to a File

[](#writing-to-a-file)

```
require 'vendor/autoload.php';

use PhpStreams\Stream;

// Open a file for writing
$fileHandle = fopen('write.txt', 'w');

// Create a stream from the file handle
$fileStream = new Stream($fileHandle);

// Check if the stream is writable
$bytesWritten = $fileStream->isWritable() ? $fileStream->write('New text') : null;

if ($bytesWritten) {
  echo "Bytes written: $bytesWritten";
} else {
  echo "The file is not writable.";
}

// Close the file handle
fclose($fileHandle);
```

Output example (if writing is successful):

```
Bytes written: 8

```

### Reading a Specific Number of Bytes from a File

[](#reading-a-specific-number-of-bytes-from-a-file)

```
require 'vendor/autoload.php';

use PhpStreams\Stream;

// Open a file for reading
$fileHandle = fopen('example.txt', 'r');

// Create a stream from the file handle
$fileStream = new Stream($fileHandle);

// Check if the stream is readable
if ($fileStream->isReadable()) {
    // Define the exact number of bytes to read
    $numBytesToRead = 6;

    // Read 10 bytes from the file
    $data = $fileStream->read($numBytesToRead);

    // Output the read data
    echo "Read $numBytesToRead bytes of data: $data\n";

    // Read the remaining content of the file
    $remainingData = $fileStream->getContents();

    // Output the remaining data
    echo "Remaining data: $remainingData";
} else {
    echo "The file is not readable.";
}

// Close the file handle
fclose($fileHandle);
```

Output example

```
Read 6 bytes of data: Hello,
Remaining data:  my name is example.txt

```

### Getting Stream Metadata

[](#getting-stream-metadata)

```
require 'vendor/autoload.php';

use PhpStreams\Stream;

// Open a file for reading
$fileHandle = fopen('example.txt', 'r');

// Create a stream from the file handle
$fileStream = new Stream($fileHandle);

// Get metadata of the stream
$metadata = $fileStream->getMetadata();

// Output the metadata
echo "Stream metadata:\n";
print_r($metadata);

// Close the file handle
fclose($fileHandle);
```

Output example

```
Stream metadata:
Array
(
    [timed_out] =>
    [blocked] => 1
    [eof] =>
    [wrapper_type] => plainfile
    [stream_type] => STDIO
    [mode] => r
    [unread_bytes] => 0
    [seekable] => 1
    [uri] => example.txt
)

```

Contributing
------------

[](#contributing)

Want to contribute? All contributions are welcome. Read the [contributing guide](CONTRIBUTING.md).

Questions
---------

[](#questions)

If you have questions tweet me at [@sandro\_m\_m](https://twitter.com/sandro_m_m) or [open an issue](../../issues/new).

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

\*\*~ sharing is caring ~\*\*

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.3% 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 ~0 days

Total

3

Last Release

794d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6b082015ff3afef14c40ed5af8887ccaf378c6eaabd15aac38103ecdb5b0dc4f?d=identicon)[sandromiguel](/maintainers/sandromiguel)

---

Top Contributors

[![SandroMiguel](https://avatars.githubusercontent.com/u/6423157?v=4)](https://github.com/SandroMiguel "SandroMiguel (28 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

psr-7streamphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sandromiguel-php-streams/health.svg)

```
[![Health](https://phpackages.com/badges/sandromiguel-php-streams/health.svg)](https://phpackages.com/packages/sandromiguel-php-streams)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.2k](/packages/guzzlehttp-psr7)[genkgo/archive-stream

Stream a ZIP file (memory efficient) as a PSR-7 message

3063.0k](/packages/genkgo-archive-stream)[jsq/psr7-stream-encryption

For encrypting and decrypting streams of arbitrary size.

36134.2k1](/packages/jsq-psr7-stream-encryption)[httpsoft/http-basis

Simple and fast HTTP microframework implementing PSR standards

1334.9k1](/packages/httpsoft-http-basis)

PHPackages © 2026

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