struggle-for-php/sfp-iterator-url

迭代器的streamWrapper

0.1.1 2017-02-16 09:54 UTC

This package is auto-updated.

Last update: 2024-09-06 15:48:15 UTC


README

Build Status

迭代器的streamWrapper。

为什么?

为了避免整个缓冲。

使用(是的!内存使用!)

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