public function makeAllRequests(array $requests = [])
    {
        if (empty($requests)) {
            $requests = $this->savedRequests;
        }
        list($channels, $multiHandle) = $this->createCurlMultiHandle($requests);

        // running all requests
        $isRunning = null;
        do {
            curl_multi_exec($multiHandle, $isRunning);
        } while ($isRunning);

        // get response and close all handles
        $retryRequests = [];
        $responses = [];
        $sleepDurations = 0;
        foreach ($channels as $id => $channel) {

            $content = curl_multi_getcontent($channel);
            $response = $this->parseResponse($channel, $content);

            if ($response->statusCode() === self::TOO_MANY_REQUESTS_HTTP_CODE && $requests[$id]['retryOnLimit']) {
                $headers = $response->headers(true);
                $sleepDurations = max($sleepDurations, $headers['X-Ratelimit-Reset'] - time());
                $requestData = [
                    'method' => $requests[$id]['method'],
                    'url' => $requests[$id]['url'],
                    'body' => $requests[$id]['body'],
                    'headers' => $headers,
                ];
                $retryRequests[] = $this->createSavedRequest($requestData, false);
            } else {
                $responses[] = $response;
            }

            curl_multi_remove_handle($multiHandle, $channel);
        }
        curl_multi_close($multiHandle);

        // retry requests
        if (!empty($retryRequests)) {
            sleep($sleepDurations > 0 ? $sleepDurations : 0);
            $responses = array_merge($responses, $this->makeAllRequests($retryRequests));
        }
        return $responses;
    }
public function makeAllRequests(array $requests = [])
    {
        if (empty($requests)) {
            $requests = $this->savedRequests;
        }
        list($channels, $multiHandle) = $this->createCurlMultiHandle($requests);

        // running all requests
        $isRunning = null;
        do {
            curl_multi_exec($multiHandle, $isRunning);
        } while ($isRunning);

        // get response and close all handles
        $retryRequests = [];
        $responses = [];
        $sleepDurations = 0;
        foreach ($channels as $id => $channel) {

            $content = curl_multi_getcontent($channel);
            $response = $this->parseResponse($channel, $content);

            if ($response->statusCode() === self::TOO_MANY_REQUESTS_HTTP_CODE && $requests[$id]['retryOnLimit']) {
                $headers = $response->headers(true);
                $sleepDurations = max($sleepDurations, $headers['X-Ratelimit-Reset'] - time());
                $requestData = [
                    'method' => $requests[$id]['method'],
                    'url' => $requests[$id]['url'],
                    'body' => $requests[$id]['body'],
                    'headers' => $headers,
                ];
                $retryRequests[] = $this->createSavedRequest($requestData, false);
            } else {
                $responses[] = $response;
            }

            curl_multi_remove_handle($multiHandle, $channel);
        }
        curl_multi_close($multiHandle);

        // retry requests
        if (!empty($retryRequests)) {
            sleep($sleepDurations > 0 ? $sleepDurations : 0);
            $responses = array_merge($responses, $this->makeAllRequests($retryRequests));
        }
        return $responses;
    }
public function makeAllRequests ( array $ requests = [ ] ) { if ( empty ( $ requests ) ) { $ requests = $ this -> savedRequests ; } list ( $ channels , $ multiHandle ) = $ this -> createCurlMultiHandle ( $ requests ) ; // running all requests $ isRunning = null ; do { curl_multi_exec ( $ multiHandle , $ isRunning ) ; } while ( $ isRunning ) ; // get response and close all handles $ retryRequests = [ ] ; $ responses = [ ] ; $ sleepDurations = 0 ; foreach ( $ channels as $ id => $ channel ) { $ content = curl_multi_getcontent ( $ channel ) ; $ response = $ this -> parseResponse ( $ channel , $ content ) ; if ( $ response -> statusCode ( ) === self :: TOO_MANY_REQUESTS_HTTP_CODE && $ requests [ $ id ] [ 'retryOnLimit' ] ) { $ headers = $ response -> headers ( true ) ; $ sleepDurations = max ( $ sleepDurations , $ headers [ 'X-Ratelimit-Reset' ] - time ( ) ) ; $ requestData = [ 'method' => $ requests [ $ id ] [ 'method' ] , 'url' => $ requests [ $ id ] [ 'url' ] , 'body' => $ requests [ $ id ] [ 'body' ] , 'headers' => $ headers , ] ; $ retryRequests [ ] = $ this -> createSavedRequest ( $ requestData , false ) ; } else { $ responses [ ] = $ response ; } curl_multi_remove_handle ( $ multiHandle , $ channel ) ; } curl_multi_close ( $ multiHandle ) ; // retry requests if ( ! empty ( $ retryRequests ) ) { sleep ( $ sleepDurations > 0 ? $ sleepDurations : 0 ) ; $ responses = array_merge ( $ responses , $ this -> makeAllRequests ( $ retryRequests ) ) ; } return $ responses ; }
Send all saved requests at once

@param array $requests

@return Response[]
Send all saved requests at once