public function stream($url, array $query, callable $eventListener)
    {
        try {
            $response = $this->guzzleClient->request
            (
                'GET',
                $this->fullUrl($url),
                $this->getRequestOptions
                (
                    [
                        'stream' => true, 
                        'query' => $this->mergeQuery($url, $query),
                        'headers' =>
                            [
                                'Accept' => 'text/event-stream'
                            ]
                    ]
                )
            );
        } catch (RequestException $exception) {
            if ($exception->hasResponse()) {
                $response = $exception->getResponse();
            } else {
                return 500;
            }
        }

        if (strpos($response->getHeader('Content-Type')[0], 'text/event-stream') !== false) {
            $this->handleStreamBody($response->getBody(), $eventListener);
        } elseif ($this->isJsonResponse($response)) {
            $responseData = $this->decodeJson($response->getBody());
            $eventListener(['type' => '', 'id' => '', 'data' => $responseData]);
        }

        return $response->getStatusCode();
    }
public function stream($url, array $query, callable $eventListener)
    {
        try {
            $response = $this->guzzleClient->request
            (
                'GET',
                $this->fullUrl($url),
                $this->getRequestOptions
                (
                    [
                        'stream' => true, 
                        'query' => $this->mergeQuery($url, $query),
                        'headers' =>
                            [
                                'Accept' => 'text/event-stream'
                            ]
                    ]
                )
            );
        } catch (RequestException $exception) {
            if ($exception->hasResponse()) {
                $response = $exception->getResponse();
            } else {
                return 500;
            }
        }

        if (strpos($response->getHeader('Content-Type')[0], 'text/event-stream') !== false) {
            $this->handleStreamBody($response->getBody(), $eventListener);
        } elseif ($this->isJsonResponse($response)) {
            $responseData = $this->decodeJson($response->getBody());
            $eventListener(['type' => '', 'id' => '', 'data' => $responseData]);
        }

        return $response->getStatusCode();
    }
public function stream ( $ url , array $ query , callable $ eventListener ) { try { $ response = $ this -> guzzleClient -> request ( 'GET' , $ this -> fullUrl ( $ url ) , $ this -> getRequestOptions ( [ 'stream' => true , 'query' => $ this -> mergeQuery ( $ url , $ query ) , 'headers' => [ 'Accept' => 'text/event-stream' ] ] ) ) ; } catch ( RequestException $ exception ) { if ( $ exception -> hasResponse ( ) ) { $ response = $ exception -> getResponse ( ) ; } else { return 500 ; } } if ( strpos ( $ response -> getHeader ( 'Content-Type' ) [ 0 ] , 'text/event-stream' ) !== false ) { $ this -> handleStreamBody ( $ response -> getBody ( ) , $ eventListener ) ; } elseif ( $ this -> isJsonResponse ( $ response ) ) { $ responseData = $ this -> decodeJson ( $ response -> getBody ( ) ) ; $ eventListener ( [ 'type' => '' , 'id' => '' , 'data' => $ responseData ] ) ; } return $ response -> getStatusCode ( ) ; }
Request object stream

@see https://html.spec.whatwg.org/multipage/comms.html#server-sent-events

@param string $url
@param array $query
@param callable $eventListener Callback function with a single parameter (associative array of type, id, data)
@return int HTTP status code
Request object stream