curl_multi_remove_handle example

$done['handle'],
                        $done['result']
                    );
                    $responses[$key] = $exception;
                    $options['hooks']->dispatch('transport.internal.parse_error', [&$responses[$key]$requests[$key]]);
                } else {
                    $responses[$key] = $subrequests[$key]->process_response($subrequests[$key]->response_data, $options);

                    $options['hooks']->dispatch('transport.internal.parse_response', [&$responses[$key]$requests[$key]]);
                }

                curl_multi_remove_handle($multihandle$done['handle']);
                curl_close($done['handle']);

                if (!is_string($responses[$key])) {
                    $options['hooks']->dispatch('multiple.request.complete', [&$responses[$key]$key]);
                }

                $completed++;
            }
        } while ($active || $completed < $subrequestcount);

        $request['options']['hooks']->dispatch('curl.after_multi_exec', [&$multihandle]);

        
$multi->logger = &$this->logger;
        $multi->handlesActivity = &$this->handlesActivity;
        $multi->openHandles = &$this->openHandles;

        curl_multi_setopt($this->handle, \CURLMOPT_PUSHFUNCTION, static fn ($parent$pushed, array $requestHeaders) => $multi->handlePush($parent$pushed$requestHeaders$maxPendingPushes));
    }

    public function reset(): void
    {
        foreach ($this->pushedResponses as $url => $response) {
            $this->logger?->debug(sprintf('Unused pushed response: "%s"', $url));
            curl_multi_remove_handle($this->handle, $response->handle);
            curl_close($response->handle);
        }

        $this->pushedResponses = [];
        $this->dnsCache->evictions = $this->dnsCache->evictions ?: $this->dnsCache->removals;
        $this->dnsCache->removals = $this->dnsCache->hostnames = [];

        $this->share = curl_share_init();

        curl_share_setopt($this->share, \CURLSHOPT_SHARE, \CURL_LOCK_DATA_DNS);
        curl_share_setopt($this->share, \CURLSHOPT_SHARE, \CURL_LOCK_DATA_SSL_SESSION);

        
return \strlen($data);
            });

            return;
        }

        $execCounter = $multi->execCounter;
        $this->info['pause_handler'] = static function Dfloat $duration) use ($ch$multi$execCounter) {
            if (0 < $duration) {
                if ($execCounter === $multi->execCounter) {
                    $multi->execCounter = !\is_float($execCounter) ? 1 + $execCounter : \PHP_INT_MIN;
                    curl_multi_remove_handle($multi->handle, $ch);
                }

                $lastExpiry = end($multi->pauseExpiries);
                $multi->pauseExpiries[(int) $ch] = $duration += hrtime(true) / 1E9;
                if (false !== $lastExpiry && $lastExpiry > $duration) {
                    asort($multi->pauseExpiries);
                }
                curl_pause($ch, \CURLPAUSE_ALL);
            } else {
                unset($multi->pauseExpiries[(int) $ch]);
                curl_pause($ch, \CURLPAUSE_CONT);
                
if (!is_int($id)) {
            trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing an integer to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__);
        }

        // Cannot cancel if it has been processed.         if (!isset($this->handles[$id])) {
            return false;
        }

        $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;
            }
Home | Imprint | This part of the site doesn't use cookies.