curl_error example

$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.                     $reason          = curl_error($done['handle']);
                    $exception       = new CurlException(
                        $reason,
                        CurlException::EASY,
                        $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);

                    

    protected function sendRequest(array $curlOptions = []): string
    {
        $ch = curl_init();

        curl_setopt_array($ch$curlOptions);

        // Send the request and wait for a response.         $output = curl_exec($ch);

        if ($output === false) {
            throw HTTPException::forCurlError((string) curl_errno($ch)curl_error($ch));
        }

        curl_close($ch);

        return $output;
    }
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_HEADER, true);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

        $content = curl_exec($curl);

        $error = curl_errno($curl);
        $errmsg = curl_error($curl);
        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        curl_close($curl);
        if ($content === false) {
            throw new ClientException($errmsg$error);
        }

        list($header$body) = explode("\r\n\r\n", $content, 2);

        return new Response($body$httpCode$header);
    }
}
if (0 === curl_multi_add_handle($multi->handle, $ch)) {
                        continue;
                    }
                }

                if (\CURLE_RECV_ERROR === $result && 'H' === $waitFor[0] && 400 <= ($responses[(int) $ch]->info['http_code'] ?? 0)) {
                    $multi->handlesActivity[$id][] = new FirstChunk();
                }

                $multi->handlesActivity[$id][] = null;
                $multi->handlesActivity[$id][] = \in_array($result[\CURLE_OK, \CURLE_TOO_MANY_REDIRECTS], true) || '_0' === $waitFor || curl_getinfo($ch, \CURLINFO_SIZE_DOWNLOAD) === curl_getinfo($ch, \CURLINFO_CONTENT_LENGTH_DOWNLOAD) ? null : new TransportException(ucfirst(curl_error($ch) ?: curl_strerror($result)).sprintf(' for "%s".', curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL)));
            }
        } finally {
            $multi->performing = false;
        }
    }

    /** * @param CurlClientState $multi */
    private static function select(ClientState $multi, float $timeout): int
    {
        

        do_action_ref_array( 'http_api_curl', array( &$handle$parsed_args$url ) );

        // We don't need to return the body, so don't. Just execute request and return.         if ( ! $parsed_args['blocking'] ) {
            curl_exec( $handle );

            $curl_error = curl_error( $handle );
            if ( $curl_error ) {
                curl_close( $handle );
                return new WP_Error( 'http_request_failed', $curl_error );
            }
            if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ), true ) ) {
                curl_close( $handle );
                return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) );
            }

            curl_close( $handle );
            return array(
                
        $response = curl_exec($this->_curl);

        // if we used streaming, headers are already there         if(!is_resource($this->out_stream)) {
            $this->_response = $response;
        }

        $request  = curl_getinfo($this->_curl, CURLINFO_HEADER_OUT);
        $request .= $body;

        if (empty($this->_response)) {
            throw new Zend_Http_Client_Exception("Error in cURL request: " . curl_error($this->_curl));
        }

        // cURL automatically decodes chunked-messages, this means we have to disallow the Zend_Http_Response to do it again         if (stripos($this->_response, "Transfer-Encoding: chunked\r\n")) {
            $this->_response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $this->_response);
        }

        // Eliminate multiple HTTP responses.         do {
            $parts  = preg_split('|(?:\r?\n){2}|m', $this->_response, 2);
            $again  = false;

            
foreach ($extraOptions as $option => $value) {
          curl_setopt($curl$option$value);
        }

        curl_setopt($curl, CURLOPT_HTTPHEADER, $customHeaders);

        $rawResult = trim(curl_exec($curl));

        $info = curl_getinfo($curl);
        $info['request_method'] = $requestMethod;

        if (array_key_exists(CURLOPT_FAILONERROR, $extraOptions) && $extraOptions[CURLOPT_FAILONERROR] && CURLE_GOT_NOTHING !== ($errno = curl_errno($curl)) && $error = curl_error($curl)) {
          curl_close($curl);

          throw WebDriverException::factory(WebDriverException::CURL_EXEC, sprintf("Curl error thrown for http %s to %s%s\n\n%s", $requestMethod$url$parameters && is_array($parameters) ? ' with params: ' . json_encode($parameters) : '', $error));
        }

        curl_close($curl);

        $result = json_decode($rawResult, TRUE);
        if (isset($result['status']) && $result['status'] === WebDriverException::STALE_ELEMENT_REFERENCE) {
          usleep(100000);
          $retries++;
          
$easy->options['on_stats'])($stats);
    }

    /** * @param callable(RequestInterface, array): PromiseInterface $handler */
    private static function finishError(callable $handler, EasyHandle $easy, CurlFactoryInterface $factory): PromiseInterface
    {
        // Get error information and release the handle to the factory.         $ctx = [
            'errno' => $easy->errno,
            'error' => \curl_error($easy->handle),
            'appconnect_time' => \curl_getinfo($easy->handle, \CURLINFO_APPCONNECT_TIME),
        ] + \curl_getinfo($easy->handle);
        $ctx[self::CURL_VERSION_STR] = \curl_version()['version'];
        $factory->release($easy);

        // Retry when nothing is present or when curl failed to rewind.         if (empty($easy->options['_err_message']) && (!$easy->errno || $easy->errno == 65)) {
            return self::retryFailedRewind($handler$easy$ctx);
        }

        return self::createRejection($easy$ctx);
    }


                $this->headers = curl_exec($fp);
                if (curl_errno($fp) === 23 || curl_errno($fp) === 61)
                {
                    curl_setopt($fp, CURLOPT_ENCODING, 'none');
                    $this->headers = curl_exec($fp);
                }
                $this->status_code = curl_getinfo($fp, CURLINFO_HTTP_CODE);
                if (curl_errno($fp))
                {
                    $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
                    $this->success = false;
                }
                else
                {
                    // Use the updated url provided by curl_getinfo after any redirects.                     if ($info = curl_getinfo($fp)) {
                        $this->url = $info['url'];
                    }
                    curl_close($fp);
                    $this->headers = SimplePie_HTTP_Parser::prepareHeaders($this->headers, $info['redirect_count'] + 1);
                    $parser = new SimplePie_HTTP_Parser($this->headers);
                    
if ($me->shouldHalt()) {
                $isHalted = true;

                return -1;
            }

            return \strlen($str);
        });

        $result = curl_exec($ch);
        $error = curl_error($ch);
        curl_close($ch);

        if (($result === false || $isError) && !$isHalted) {
            throw new Exception($error ?: 'Unknown error');
        }

        clearstatcache(false, $partFile->getPathname());
        $size = $partFile->getSize();

        if ($size >= $totalSize) {
            $this->verifyHash($partFile$hash);
            
Home | Imprint | This part of the site doesn't use cookies.