A streamWrapper for Iterator
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sample
src/SfpIteratorUrl
tests/SfpIteratorUrlTest
.gitignore
.travis.yml
README.md
composer.json
phpcs.xml
phpunit.xml.dist

README.md

SfpIteratorUrl

Build Status

A streamWrapper for Iterator.

Why ?

To avoid entire buffering.

Usage (Yeah! memory usage!)

class Bigsize extends IteratorIterator
{
    public function current()
    {
        $str = str_repeat($this->getInnerIterator()->current(), 8192);
        return $str;
    }
}

$iterator = new Bigsize(new ArrayIterator(range(1, 100)));
$fp = (new IteratorUrl)->open($iterator);
$body = new Zend\Diactoros\Stream($fp);

// emit
fpassthru($body->detach());

echo formatBytes(memory_get_usage());  // 278.97 KB <-- look
// echo $body->__toString();           // 1.75MB