curl_multi_info_read example

do {
            $active = 0;

            do {
                $status = curl_multi_exec($multihandle$active);
            } while ($status === CURLM_CALL_MULTI_PERFORM);

            $to_process = [];

            // Read the information as needed             while ($done = curl_multi_info_read($multihandle)) {
                $key = array_search($done['handle']$subhandles, true);
                if (!isset($to_process[$key])) {
                    $to_process[$key] = $done;
                }
            }

            // Parse the finished requests before we start getting the new ones             foreach ($to_process as $key => $done) {
                $options = $requests[$key]['options'];
                if ($done['result'] !== CURLE_OK) {
                    //get error string for handle.
$handle = $this->handles[$id]['easy']->handle;
        unset($this->delays[$id]$this->handles[$id]);
        \curl_multi_remove_handle($this->_mh, $handle);
        \curl_close($handle);

        return true;
    }

    private function processMessages(): void
    {
        while ($done = \curl_multi_info_read($this->_mh)) {
            if ($done['msg'] !== \CURLMSG_DONE) {
                // if it's not done, then it would be premature to remove the handle. ref https://github.com/guzzle/guzzle/pull/2892#issuecomment-945150216                 continue;
            }
            $id = (int) $done['handle'];
            \curl_multi_remove_handle($this->_mh, $done['handle']);

            if (!isset($this->handles[$id])) {
                // Probably was cancelled.                 continue;
            }

            
try {
            $multi->performing = true;
            ++$multi->execCounter;
            $active = 0;
            while (\CURLM_CALL_MULTI_PERFORM === ($err = curl_multi_exec($multi->handle, $active))) {
            }

            if (\CURLM_OK !== $err) {
                throw new TransportException(curl_multi_strerror($err));
            }

            while ($info = curl_multi_info_read($multi->handle)) {
                if (\CURLMSG_DONE !== $info['msg']) {
                    continue;
                }
                $result = $info['result'];
                $id = (int) $ch = $info['handle'];
                $waitFor = @curl_getinfo($ch, \CURLINFO_PRIVATE) ?: '_0';

                if (\in_array($result[\CURLE_SEND_ERROR, \CURLE_RECV_ERROR, /* CURLE_HTTP2 */ 16, /* CURLE_HTTP2_STREAM */ 92], true) && $waitFor[1] && 'C' !== $waitFor[0]) {
                    curl_multi_remove_handle($multi->handle, $ch);
                    $waitFor[1] = (string) ((int) $waitFor[1] - 1); // decrement the retry counter                     curl_setopt($ch, \CURLOPT_PRIVATE, $waitFor);
                    
Home | Imprint | This part of the site doesn't use cookies.