src/Webservice/EventsWebservice.php
protected function _stream($url, array $queryParameters)
    {
        while (true) {
            $this->_lastTime = time();

            $options = [];
            if ($this->_lastEtag) {
                $options['headers']['If-None-Match'] = $this->_lastEtag;
            }

            /* @var Response $response */
            $response = $this->driver()->client()->get($url, $queryParameters, $options);
            if ((!$response->isOk()) && ($response->statusCode() != 304)) {
                switch ($response->statusCode()) {
                    case 403:
                        if ($response->header('X-Ratelimit-Remaining') == 0) {
                            var_dump($response);
                            throw new RateLimitExceededException([$response->header('X-Ratelimit-Remaining')]);
                        }
                }

                return;
            }

            if ($response->statusCode() != 304) {
                $this->_lastEtag = $response->header('Etag');
                $this->_lastPollInterval = $response->header('X-Poll-Interval');

                $resources = array_reverse($response->json);
                foreach ($resources as $resource) {
                    if (in_array($resource['id'], $this->_lastIds)) {
                        continue;
                    }

                    array_unshift($this->_lastIds, $resource['id']);

                    yield $resource;
                }
                $this->_lastIds = array_splice($this->_lastIds, 0, 30);
            }

            $sleepingTime = $this->_lastPollInterval - (time() - $this->_lastTime);
            if ($sleepingTime > 0) {
                sleep($sleepingTime);
            }
        }
    }
protected function _stream($url, array $queryParameters)
    {
        while (true) {
            $this->_lastTime = time();

            $options = [];
            if ($this->_lastEtag) {
                $options['headers']['If-None-Match'] = $this->_lastEtag;
            }

            /* @var Response $response */
            $response = $this->driver()->client()->get($url, $queryParameters, $options);
            if ((!$response->isOk()) && ($response->statusCode() != 304)) {
                switch ($response->statusCode()) {
                    case 403:
                        if ($response->header('X-Ratelimit-Remaining') == 0) {
                            var_dump($response);
                            throw new RateLimitExceededException([$response->header('X-Ratelimit-Remaining')]);
                        }
                }

                return;
            }

            if ($response->statusCode() != 304) {
                $this->_lastEtag = $response->header('Etag');
                $this->_lastPollInterval = $response->header('X-Poll-Interval');

                $resources = array_reverse($response->json);
                foreach ($resources as $resource) {
                    if (in_array($resource['id'], $this->_lastIds)) {
                        continue;
                    }

                    array_unshift($this->_lastIds, $resource['id']);

                    yield $resource;
                }
                $this->_lastIds = array_splice($this->_lastIds, 0, 30);
            }

            $sleepingTime = $this->_lastPollInterval - (time() - $this->_lastTime);
            if ($sleepingTime > 0) {
                sleep($sleepingTime);
            }
        }
    }
protected function _stream ( $ url , array $ queryParameters ) { while ( true ) { $ this -> _lastTime = time ( ) ; $ options = [ ] ; if ( $ this -> _lastEtag ) { $ options [ 'headers' ] [ 'If-None-Match' ] = $ this -> _lastEtag ; } /* @var Response $response */ $ response = $ this -> driver ( ) -> client ( ) -> get ( $ url , $ queryParameters , $ options ) ; if ( ( ! $ response -> isOk ( ) ) && ( $ response -> statusCode ( ) != 304 ) ) { switch ( $ response -> statusCode ( ) ) { case 403 : if ( $ response -> header ( 'X-Ratelimit-Remaining' ) == 0 ) { var_dump ( $ response ) ; throw new RateLimitExceededException ( [ $ response -> header ( 'X-Ratelimit-Remaining' ) ] ) ; } } return ; } if ( $ response -> statusCode ( ) != 304 ) { $ this -> _lastEtag = $ response -> header ( 'Etag' ) ; $ this -> _lastPollInterval = $ response -> header ( 'X-Poll-Interval' ) ; $ resources = array_reverse ( $ response -> json ) ; foreach ( $ resources as $ resource ) { if ( in_array ( $ resource [ 'id' ] , $ this -> _lastIds ) ) { continue ; } array_unshift ( $ this -> _lastIds , $ resource [ 'id' ] ) ; yield $ resource ; } $ this -> _lastIds = array_splice ( $ this -> _lastIds , 0 , 30 ) ; } $ sleepingTime = $ this -> _lastPollInterval - ( time ( ) - $ this -> _lastTime ) ; if ( $ sleepingTime > 0 ) { sleep ( $ sleepingTime ) ; } } }
Stream results from the events endpoint.

@param string $url Endpoint to stream events from.
@param array $queryParameters Query parameters to send
@return \Generator|void
Stream results from the events endpoint .