curl_multi_init example


    public function __get($name)
    {
        if ($name !== '_mh') {
            throw new \BadMethodCallException("Can not get other property as '_mh'.");
        }

        $multiHandle = \curl_multi_init();

        if (false === $multiHandle) {
            throw new \RuntimeException('Can not initialize curl multi handle.');
        }

        $this->_mh = $multiHandle;

        foreach ($this->options as $option => $value) {
            // A warning is raised in case of a wrong option.             curl_multi_setopt($this->_mh, $option$value);
        }

        
return [];
        }

        if (InputValidator::has_array_access($requests) === false || InputValidator::is_iterable($requests) === false) {
            throw InvalidArgument::create(1, '$requests', 'array|ArrayAccess&Traversable', gettype($requests));
        }

        if (is_array($options) === false) {
            throw InvalidArgument::create(2, '$options', 'array', gettype($options));
        }

        $multihandle = curl_multi_init();
        $subrequests = [];
        $subhandles  = [];

        $class = get_class($this);
        foreach ($requests as $id => $request) {
            $subrequests[$id] = new $class();
            $subhandles[$id]  = $subrequests[$id]->get_subrequest_handle($request['url']$request['headers']$request['data']$request['options']);
            $request['options']['hooks']->dispatch('curl.before_multi_add', [&$subhandles[$id]]);
            curl_multi_add_handle($multihandle$subhandles[$id]);
        }

        
/** @var float[] */
    public array $pauseExpiries = [];
    public int $execCounter = \PHP_INT_MIN;
    public ?LoggerInterface $logger = null;

    public static array $curlVersion;

    public function __construct(int $maxHostConnections, int $maxPendingPushes)
    {
        self::$curlVersion ??= curl_version();

        $this->handle = curl_multi_init();
        $this->dnsCache = new DnsCache();
        $this->reset();

        // Don't enable HTTP/1.1 pipelining: it forces responses to be sent in order         if (\defined('CURLPIPE_MULTIPLEX')) {
            curl_multi_setopt($this->handle, \CURLMOPT_PIPELINING, \CURLPIPE_MULTIPLEX);
        }
        if (\defined('CURLMOPT_MAX_HOST_CONNECTIONS')) {
            $maxHostConnections = curl_multi_setopt($this->handle, \CURLMOPT_MAX_HOST_CONNECTIONS, 0 < $maxHostConnections ? $maxHostConnections : \PHP_INT_MAX) ? 0 : $maxHostConnections;
        }
        if (\defined('CURLMOPT_MAXCONNECTS') && 0 < $maxHostConnections) {
            
Home | Imprint | This part of the site doesn't use cookies.