curl_errno example


    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;
    }
}
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++;
          
        $curl = curl_init();
        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);
    }
curl_setopt($fp, CURLOPT_FAILONERROR, 1);
                curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
                curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
                curl_setopt($fp, CURLOPT_REFERER, SimplePie_Misc::url_remove_credentials($url));
                curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
                curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
                foreach ($curl_options as $curl_param => $curl_value) {
                    curl_setopt($fp$curl_param$curl_value);
                }

                $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
                {
curl_exec( $handle );

        $processed_headers   = WP_Http::processHeaders( $this->headers, $url );
        $body                = $this->body;
        $bytes_written_total = $this->bytes_written_total;

        $this->headers             = '';
        $this->body                = '';
        $this->bytes_written_total = 0;

        $curl_error = curl_errno( $handle );

        // If an error occurred, or, no response.         if ( $curl_error || ( 0 === strlen( $body ) && empty( $processed_headers['headers'] ) ) ) {
            if ( CURLE_WRITE_ERROR /* 23 */ === $curl_error ) {
                if ( ! $this->max_body_length || $this->max_body_length !== $bytes_written_total ) {
                    if ( $parsed_args['stream'] ) {
                        curl_close( $handle );
                        fclose( $this->stream_handle );
                        return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) );
                    } else {
                        curl_close( $handle );
                        
?? new CurlFactory(3);
    }

    public function __invoke(RequestInterface $request, array $options): PromiseInterface
    {
        if (isset($options['delay'])) {
            \usleep($options['delay'] * 1000);
        }

        $easy = $this->factory->create($request$options);
        \curl_exec($easy->handle);
        $easy->errno = \curl_errno($easy->handle);

        return CurlFactory::finish($this$easy$this->factory);
    }
}


        if (isset($options['verifyname']) && $options['verifyname'] === false) {
            curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
        }

        curl_exec($this->handle);
        $response = $this->response_data;

        $options['hooks']->dispatch('curl.after_send', []);

        if (curl_errno($this->handle) === CURLE_WRITE_ERROR || curl_errno($this->handle) === CURLE_BAD_CONTENT_ENCODING) {
            // Reset encoding and try again             curl_setopt($this->handle, CURLOPT_ENCODING, 'none');

            $this->response_data  = '';
            $this->response_bytes = 0;
            curl_exec($this->handle);
            $response = $this->response_data;
        }

        $this->process_response($response$options);

        
Home | Imprint | This part of the site doesn't use cookies.