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

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

phpro/resource-stream
=====================

A safe OOP wrapper around resource streams

1.3.0(7mo ago)127.3k↓11.1%11MITPHPPHP ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Oct 18Pushed 5mo ago5 watchersCompare

[ Source](https://github.com/phpro/resource-stream)[ Packagist](https://packagist.org/packages/phpro/resource-stream)[ RSS](/packages/phpro-resource-stream/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (7)Versions (7)Used By (1)

Resource Stream
===============

[](#resource-stream)

A safe OOP wrapper around resource [streams](https://www.php.net/manual/en/book.stream.php) in PHP:

- No need to worry about streams that have been closed.
- Instead of returning `false`, detailed exceptions are thrown when something goes wrong.
- Streams are automatically closed when the object is destructed (with option to opt-out).
- Handy factory methods for common streams.

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

[](#installation)

```
composer require phpro/resource-stream
```

Usage
-----

[](#usage)

```
use Phpro\ResourceStream\ResourceStream;

$stream = (new ResourceStream(fopen('php://temp', 'r+')))
    ->write('Hello World')
    ->rewind();

// Various ways to read:
echo $stream->read();
echo $stream->read($bufferSize);
echo $stream->readLine();
echo $stream->readLine($bufferSize, ending: \PHP_EOL);
echo $stream->getContents();

// Or in batches (Generator)
$cursor = $stream->readBatches($bufferSize);
$cursor = $stream->readLines($bufferSize, ending: \PHP_EOL);

// Get access to PHP's inner resource stream
$innerStream = $stream->unwrap();

// Get access to common information:
$stream->isOpen();
$stream->isEof();
$stream->uri();
$stream->size();

// Possibility to copy contents across streams
$stream->copyTo($anotherStream);
$stream->copyFrom($anotherStream);

// Streams will automatically be closed on destruction.
// Of course, you can choose to keep it open or close it manually:
$stream->keepAlive();
$stream->close();
```

Built-in Streams
----------------

[](#built-in-streams)

The following streams are available by default:

### CliStream

[](#clistream)

Can be used to open up CLI `stdin`, `stdout` and `stderr` streams.

```
use Phpro\ResourceStream\Factory\CliStream;

$stdin = CliStream::stdin();
$stdout = CliStream::stdout();
$stderr = CliStream::stderr();
```

### FileStream

[](#filestream)

Validates if the local file exists and opens it up for you to use.

```
use Phpro\ResourceStream\Factory\FileStream;

$stream = FileStream::create('/path/to/file', FileStream::READ_WRITE_MODE);
```

### IOStream

[](#iostream)

Can be used to open up CGI `php://input` and `php://output` streams.

```
use Phpro\ResourceStream\Factory\IOStream;

$input = IOStream::input();
$output = IOStream::output();
```

### MemoryStream

[](#memorystream)

Creates an in-memory stream for you to use.

```
use Phpro\ResourceStream\Factory\MemoryStream;

$stream = MemoryStream::create();
```

### Psr7Stream

[](#psr7stream)

Creates a stream from a PSR-7 stream / request / response. before you can use this stream, you'll need to install the `guzzlehttp/psr-7` package which contains a stream wrapper implementation.

```
composer require psr/http-message guzzlehttp/psr-7
```

```
use Phpro\ResourceStream\Factory\Psr7Stream;

$stream = Psr7Stream::createFromStream($anyPsr7Stream);
$stream = Psr7Stream::createFromRequest($anyPsr7Request);
$stream = Psr7Stream::createFromResponse($anyPsr7Response);
```

### TmpStream

[](#tmpstream)

Creates a temporary file and opens it up for you to use. After the stream is closed, the temporary file will be removed.

```
use Phpro\ResourceStream\Factory\TmpStream;

$stream = TmpStream::create();
```

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance68

Regular maintenance activity

Popularity32

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 83.8% 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 ~73 days

Recently: every ~91 days

Total

6

Last Release

210d ago

PHP version history (2 changes)1.0.0PHP ^8.1

1.3.0PHP ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

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

---

Top Contributors

[![veewee](https://avatars.githubusercontent.com/u/1618158?v=4)](https://github.com/veewee "veewee (31 commits)")[![stefliekens](https://avatars.githubusercontent.com/u/3245491?v=4)](https://github.com/stefliekens "stefliekens (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[wi1dcard/baidu-mini-program-sdk

百度小程序第三方 PHP SDK，助力智能小程序开发。

544.0k1](/packages/wi1dcard-baidu-mini-program-sdk)[werfu/magento2-url-key-mask

Enable Product and Category URL\_key generation using masks

135.4k](/packages/werfu-magento2-url-key-mask)

PHPackages © 2026

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