public function poll(): bool
    {
        // nothing to do?
        if (!$this->curlMultiMap) {
            return false;
        }

        do {
            $r = curl_multi_exec(
                $this->curlMultiHandle,
                $stillRunning
            );
        } while (CURLM_CALL_MULTI_PERFORM === $r);

        $messagesInQueue = 0;
        do {
            messageQueue:

            $status = curl_multi_info_read(
                $this->curlMultiHandle,
                $messagesInQueue
            );

            if ($status && CURLMSG_DONE === $status['msg']) {
                $resourceId = (int) $status['handle'];
                list(
                    $request,
                    $successCallback,
                    $errorCallback,
                    $retryCount) = $this->curlMultiMap[$resourceId];
                unset($this->curlMultiMap[$resourceId]);

                $curlHandle = $status['handle'];
                $curlResult = $this->parseResponse(curl_multi_getcontent($curlHandle), $curlHandle);
                $retry = false;

                if (self::STATUS_CURLERROR === $curlResult['status']) {
                    $e = new ClientException($curlResult['curl_errmsg'], $curlResult['curl_errno']);
                    $this->emit('exception', [$request, $e, &$retry, $retryCount]);

                    if ($retry) {
                        ++$retryCount;
                        $this->sendAsyncInternal($request, $successCallback, $errorCallback, $retryCount);
                        goto messageQueue;
                    }

                    $curlResult['request'] = $request;

                    if ($errorCallback) {
                        $errorCallback($curlResult);
                    }
                } elseif (self::STATUS_HTTPERROR === $curlResult['status']) {
                    $this->emit('error', [$request, $curlResult['response'], &$retry, $retryCount]);
                    $this->emit('error:'.$curlResult['http_code'], [$request, $curlResult['response'], &$retry, $retryCount]);

                    if ($retry) {
                        ++$retryCount;
                        $this->sendAsyncInternal($request, $successCallback, $errorCallback, $retryCount);
                        goto messageQueue;
                    }

                    $curlResult['request'] = $request;

                    if ($errorCallback) {
                        $errorCallback($curlResult);
                    }
                } else {
                    $this->emit('afterRequest', [$request, $curlResult['response']]);

                    if ($successCallback) {
                        $successCallback($curlResult['response']);
                    }
                }
            }
        } while ($messagesInQueue > 0);

        return count($this->curlMultiMap) > 0;
    }
public function poll(): bool
    {
        // nothing to do?
        if (!$this->curlMultiMap) {
            return false;
        }

        do {
            $r = curl_multi_exec(
                $this->curlMultiHandle,
                $stillRunning
            );
        } while (CURLM_CALL_MULTI_PERFORM === $r);

        $messagesInQueue = 0;
        do {
            messageQueue:

            $status = curl_multi_info_read(
                $this->curlMultiHandle,
                $messagesInQueue
            );

            if ($status && CURLMSG_DONE === $status['msg']) {
                $resourceId = (int) $status['handle'];
                list(
                    $request,
                    $successCallback,
                    $errorCallback,
                    $retryCount) = $this->curlMultiMap[$resourceId];
                unset($this->curlMultiMap[$resourceId]);

                $curlHandle = $status['handle'];
                $curlResult = $this->parseResponse(curl_multi_getcontent($curlHandle), $curlHandle);
                $retry = false;

                if (self::STATUS_CURLERROR === $curlResult['status']) {
                    $e = new ClientException($curlResult['curl_errmsg'], $curlResult['curl_errno']);
                    $this->emit('exception', [$request, $e, &$retry, $retryCount]);

                    if ($retry) {
                        ++$retryCount;
                        $this->sendAsyncInternal($request, $successCallback, $errorCallback, $retryCount);
                        goto messageQueue;
                    }

                    $curlResult['request'] = $request;

                    if ($errorCallback) {
                        $errorCallback($curlResult);
                    }
                } elseif (self::STATUS_HTTPERROR === $curlResult['status']) {
                    $this->emit('error', [$request, $curlResult['response'], &$retry, $retryCount]);
                    $this->emit('error:'.$curlResult['http_code'], [$request, $curlResult['response'], &$retry, $retryCount]);

                    if ($retry) {
                        ++$retryCount;
                        $this->sendAsyncInternal($request, $successCallback, $errorCallback, $retryCount);
                        goto messageQueue;
                    }

                    $curlResult['request'] = $request;

                    if ($errorCallback) {
                        $errorCallback($curlResult);
                    }
                } else {
                    $this->emit('afterRequest', [$request, $curlResult['response']]);

                    if ($successCallback) {
                        $successCallback($curlResult['response']);
                    }
                }
            }
        } while ($messagesInQueue > 0);

        return count($this->curlMultiMap) > 0;
    }
public function poll ( ) : bool { // nothing to do? if ( ! $ this -> curlMultiMap ) { return false ; } do { $ r = curl_multi_exec ( $ this -> curlMultiHandle , $ stillRunning ) ; } while ( CURLM_CALL_MULTI_PERFORM === $ r ) ; $ messagesInQueue = 0 ; do { messageQueue : $ status = curl_multi_info_read ( $ this -> curlMultiHandle , $ messagesInQueue ) ; if ( $ status && CURLMSG_DONE === $ status [ 'msg' ] ) { $ resourceId = ( int ) $ status [ 'handle' ] ; list ( $ request , $ successCallback , $ errorCallback , $ retryCount ) = $ this -> curlMultiMap [ $ resourceId ] ; unset ( $ this -> curlMultiMap [ $ resourceId ] ) ; $ curlHandle = $ status [ 'handle' ] ; $ curlResult = $ this -> parseResponse ( curl_multi_getcontent ( $ curlHandle ) , $ curlHandle ) ; $ retry = false ; if ( self :: STATUS_CURLERROR === $ curlResult [ 'status' ] ) { $ e = new ClientException ( $ curlResult [ 'curl_errmsg' ] , $ curlResult [ 'curl_errno' ] ) ; $ this -> emit ( 'exception' , [ $ request , $ e , & $ retry , $ retryCount ] ) ; if ( $ retry ) { ++ $ retryCount ; $ this -> sendAsyncInternal ( $ request , $ successCallback , $ errorCallback , $ retryCount ) ; goto messageQueue ; } $ curlResult [ 'request' ] = $ request ; if ( $ errorCallback ) { $ errorCallback ( $ curlResult ) ; } } elseif ( self :: STATUS_HTTPERROR === $ curlResult [ 'status' ] ) { $ this -> emit ( 'error' , [ $ request , $ curlResult [ 'response' ] , & $ retry , $ retryCount ] ) ; $ this -> emit ( 'error:' . $ curlResult [ 'http_code' ] , [ $ request , $ curlResult [ 'response' ] , & $ retry , $ retryCount ] ) ; if ( $ retry ) { ++ $ retryCount ; $ this -> sendAsyncInternal ( $ request , $ successCallback , $ errorCallback , $ retryCount ) ; goto messageQueue ; } $ curlResult [ 'request' ] = $ request ; if ( $ errorCallback ) { $ errorCallback ( $ curlResult ) ; } } else { $ this -> emit ( 'afterRequest' , [ $ request , $ curlResult [ 'response' ] ] ) ; if ( $ successCallback ) { $ successCallback ( $ curlResult [ 'response' ] ) ; } } } } while ( $ messagesInQueue > 0 ) ; return count ( $ this -> curlMultiMap ) > 0 ; }
This method checks if any http requests have gotten results, and if so,
call the appropriate success or error handlers.

This method will return true if there are still requests waiting to
return, and false if all the work is done.
This method checks if any http requests have gotten results and if so call the appropriate success or error handlers .