src/Http/Response.php
public function push($data, $atomic = true, $options = [])
    {
        $headers = $this->headers();
        if ($headers['Transfer-Encoding']->value() !== 'chunked') {
            throw new NetException("Pushing is only supported in chunked transfer.");
        }

        $defaults = [
            'cast'   => true,
            'atomic' => true,
            'stream' => [],
            'encode' => []
        ];

        $options += $defaults;

        if ($data instanceof StreamInterface) {
            $stream = $data;
        } else {
            if ($options['cast']) {
                $media = $this->_classes['media'];
                $format = $this->format();

                if (!$format && !is_string($data)) {
                    throw new NetException("The data must be a string when no format is defined.");
                }
                $data = $media::encode($format, $data, $options['encode'], $this);
            }
            $stream = new Part(['data' => $data] + $options['stream']);
        }

        $length = $options['atomic'] && $stream->isSeekable() ? $stream->length() : $this->chunkSize();

        if ($stream->isSeekable()) {
            $stream->rewind();
        }

        while (!$stream->eof()) {
            $chunk = $stream->read($length);
            $readed = strlen($chunk);
            if (!$readed) {
                break;
            }
            echo dechex($readed) . "\r\n" . $chunk . "\r\n";
            if (connection_status() !== CONNECTION_NORMAL) {
                break;
            }
        }
        $stream->close();
    }
public function push($data, $atomic = true, $options = [])
    {
        $headers = $this->headers();
        if ($headers['Transfer-Encoding']->value() !== 'chunked') {
            throw new NetException("Pushing is only supported in chunked transfer.");
        }

        $defaults = [
            'cast'   => true,
            'atomic' => true,
            'stream' => [],
            'encode' => []
        ];

        $options += $defaults;

        if ($data instanceof StreamInterface) {
            $stream = $data;
        } else {
            if ($options['cast']) {
                $media = $this->_classes['media'];
                $format = $this->format();

                if (!$format && !is_string($data)) {
                    throw new NetException("The data must be a string when no format is defined.");
                }
                $data = $media::encode($format, $data, $options['encode'], $this);
            }
            $stream = new Part(['data' => $data] + $options['stream']);
        }

        $length = $options['atomic'] && $stream->isSeekable() ? $stream->length() : $this->chunkSize();

        if ($stream->isSeekable()) {
            $stream->rewind();
        }

        while (!$stream->eof()) {
            $chunk = $stream->read($length);
            $readed = strlen($chunk);
            if (!$readed) {
                break;
            }
            echo dechex($readed) . "\r\n" . $chunk . "\r\n";
            if (connection_status() !== CONNECTION_NORMAL) {
                break;
            }
        }
        $stream->close();
    }
public function push ( $ data , $ atomic = true , $ options = [ ] ) { $ headers = $ this -> headers ( ) ; if ( $ headers [ 'Transfer-Encoding' ] -> value ( ) !== 'chunked' ) { throw new NetException ( "Pushing is only supported in chunked transfer." ) ; } $ defaults = [ 'cast' => true , 'atomic' => true , 'stream' => [ ] , 'encode' => [ ] ] ; $ options += $ defaults ; if ( $ data instanceof StreamInterface ) { $ stream = $ data ; } else { if ( $ options [ 'cast' ] ) { $ media = $ this -> _classes [ 'media' ] ; $ format = $ this -> format ( ) ; if ( ! $ format && ! is_string ( $ data ) ) { throw new NetException ( "The data must be a string when no format is defined." ) ; } $ data = $ media :: encode ( $ format , $ data , $ options [ 'encode' ] , $ this ) ; } $ stream = new Part ( [ 'data' => $ data ] + $ options [ 'stream' ] ) ; } $ length = $ options [ 'atomic' ] && $ stream -> isSeekable ( ) ? $ stream -> length ( ) : $ this -> chunkSize ( ) ; if ( $ stream -> isSeekable ( ) ) { $ stream -> rewind ( ) ; } while ( ! $ stream -> eof ( ) ) { $ chunk = $ stream -> read ( $ length ) ; $ readed = strlen ( $ chunk ) ; if ( ! $ readed ) { break ; } echo dechex ( $ readed ) . "\r\n" . $ chunk . "\r\n" ; if ( connection_status ( ) !== CONNECTION_NORMAL ) { break ; } } $ stream -> close ( ) ; }
Push additionnal data to a chunked response.

@param mixed   $data   The formated data. If the passed data is a stream it'll be closed.
@param boolean $atomic Indicates if the $data can be chunked or must be send as a whole chunk.
Push additionnal data to a chunked response .