Nyholm / psr7

A super lightweight PSR-7 implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature request for a non-buffered stream (NonBufferedStream)

manueldimmler opened this issue · comments

At the moment, it's not possible to use server-sent events with this implementation.

When calling StreamInterface::write, the content should be echoed and flushed immediately. In addition, the header would have to be emitted immediately in the Response class if the NonBufferedStream is used as the body.

Possible implementation of StreamInterface::write in a new NonBufferedStream class

    public function write($string): int
    {
        $buffered = '';
        while (0 < \ob_get_level()) {
            $buffered = \ob_get_clean() . $buffered;
        }

        echo $buffered . $string;

        \flush();

        return \strlen($string) + \strlen($buffered);
    }

Additional lines needed in MessageTrait::withHeader

        if ($this->stream instanceof NonBufferedStream) {
            header($normalized . ': ' . \implode(', ', $value));
        }

Hm.. I dont really understand. Why would you hold the full response in memory? How would that help you with the article you linked?

Also, what is the issue using the normal Stream?

Closing as stalled.