curl_init example

return $curlOptions;
    }

    /** * Does the actual work of initializing cURL, setting the options, * and grabbing the output. * * @codeCoverageIgnore */
    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);

        
CURLOPT_FAILONERROR => TRUE,
    ];
    $retries = 0;
    $max_retries = static::$retry ? 10 : 1;
    while ($retries < $max_retries) {
      try {
        $customHeaders = [
          'Content-Type: application/json;charset=UTF-8',
          'Accept: application/json;charset=UTF-8',
        ];

        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

        switch ($requestMethod) {
          case 'GET':
            break;

          case 'POST':
            if ($parameters && is_array($parameters)) {
              curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($parameters));
            }
            else {
              

                $useragent = ini_get('user_agent');
                $this->useragent = $useragent;
            }
            if (!is_array($headers))
            {
                $headers = array();
            }
            if (!$force_fsockopen && function_exists('curl_exec'))
            {
                $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
                $fp = curl_init();
                $headers2 = array();
                foreach ($headers as $key => $value)
                {
                    $headers2[] = "$key: $value";
                }
                if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>='))
                {
                    curl_setopt($fp, CURLOPT_ENCODING, '');
                }
                curl_setopt($fp, CURLOPT_URL, $url);
                curl_setopt($fp, CURLOPT_HEADER, 1);
                
// If we are connected to a different server or port, disconnect first         if ($this->_curl
            && is_array($this->_connected_to)
            && ($this->_connected_to[0] != $host
            || $this->_connected_to[1] != $port)
        ) {
            $this->close();
        }

        // Do the actual connection         $this->_curl = curl_init();
        if ($port != 80) {
            curl_setopt($this->_curl, CURLOPT_PORT, intval($port));
        }

        // Set timeout         curl_setopt($this->_curl, CURLOPT_CONNECTTIMEOUT, $this->_config['timeout']);

        // Set Max redirects         curl_setopt($this->_curl, CURLOPT_MAXREDIRS, $this->_config['maxredirects']);

        if (!$this->_curl) {
            
// Reinitialize the pushed response with request's options                 $ch = $pushedResponse->handle;
                $pushedResponse = $pushedResponse->response;
                $pushedResponse->__construct($this->multi, $url$options$this->logger);
            } else {
                $this->logger?->debug(sprintf('Rejecting pushed response: "%s"', $url));
                $pushedResponse = null;
            }
        }

        if (!$pushedResponse) {
            $ch = curl_init();
            $this->logger?->info(sprintf('Request: "%s %s"', $method$url));
            $curlopts += [\CURLOPT_SHARE => $this->multi->share];
        }

        foreach ($curlopts as $opt => $value) {
            if (null !== $value && !curl_setopt($ch$opt$value) && \CURLOPT_CERTINFO !== $opt && (!\defined('CURLOPT_HEADEROPT') || \CURLOPT_HEADEROPT !== $opt)) {
                $constantName = $this->findConstantName($opt);
                throw new TransportException(sprintf('Curl option "%s" is not supported.', $constantName ?? $opt));
            }
        }

        


    /** * @param array<mixed> $logs */
    private function sendLogs(array $logs): void
    {
        if ($logs === []) {
            return;
        }

        $ch = \curl_init('https://http-intake.logs.datadoghq.eu/v1/input');
        \assert($ch instanceof \CurlHandle);
        \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'POST');
        \curl_setopt($ch, \CURLOPT_POST, true);
        \curl_setopt($ch, \CURLOPT_POSTFIELDS, \json_encode($logs, \JSON_THROW_ON_ERROR));
        \curl_setopt($ch, \CURLOPT_HTTPHEADER, [
            'Content-Type: application/json',
            'DD-API-KEY: ' . $_SERVER['DATADOG_API_KEY'],
        ]);

        \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, true);
        \curl_exec($ch);
        
$this->applyMethod($easy$conf);
        $this->applyHandlerOptions($easy$conf);
        $this->applyHeaders($easy$conf);
        unset($conf['_headers']);

        // Add handler options from the request configuration options         if (isset($options['curl'])) {
            $conf = \array_replace($conf$options['curl']);
        }

        $conf[\CURLOPT_HEADERFUNCTION] = $this->createHeaderFn($easy);
        $easy->handle = $this->handles ? \array_pop($this->handles) : \curl_init();
        curl_setopt_array($easy->handle, $conf);

        return $easy;
    }

    public function release(EasyHandle $easy): void
    {
        $resource = $easy->handle;
        unset($easy->handle);

        if (\count($this->handles) >= $this->maxHandles) {
            
return 0;
        }

        $range = $size . '-' . ($totalSize - 1);

        if (!\function_exists('curl_init')) {
            throw new Exception('PHP Extension "curl" is required to download a file');
        }

        // Configuration of curl         $ch = curl_init();

        curl_setopt($ch, CURLOPT_RANGE, $range);
        curl_setopt($ch, CURLOPT_URL, $sourceUri);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_NOPROGRESS, false);

        curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function D$ch$dltotal$dlnow) use ($size) {
            if ($dlnow > 0) {
                
private function call($url$method = self::METHOD_GET, array $header = []$data = null)
    {
        if (!\in_array($method$this->validMethods)) {
            throw new ClientException('Invalid HTTP-METHOD: ' . $method);
        }

        if (!filter_var($url, FILTER_VALIDATE_URL)) {
            throw new ClientException('Invalid URL given');
        }

        // Initializes the cURL instance         $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);
        

  protected function getHeaders($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, TRUE);
    curl_setopt($ch, CURLOPT_NOBODY, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, drupal_generate_test_ua($this->databasePrefix));
    $output = curl_exec($ch);
    curl_close($ch);

    $headers = [];
    foreach (explode("\n", $output) as $header) {
      if (strpos($header, ':')) {
        [

    private $response_byte_limit;

    /** * Constructor */
    public function __construct() {
        $curl          = curl_version();
        $this->version = $curl['version_number'];
        $this->handle  = curl_init();

        curl_setopt($this->handle, CURLOPT_HEADER, false);
        curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, 1);
        if ($this->version >= self::CURL_7_10_5) {
            curl_setopt($this->handle, CURLOPT_ENCODING, '');
        }

        if (defined('CURLOPT_PROTOCOLS')) {
            // phpcs:ignore PHPCompatibility.Constants.NewConstants.curlopt_protocolsFound             curl_setopt($this->handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
        }

        
if ( isset( $parsed_args['headers']['User-Agent'] ) ) {
            $parsed_args['user-agent'] = $parsed_args['headers']['User-Agent'];
            unset( $parsed_args['headers']['User-Agent'] );
        } elseif ( isset( $parsed_args['headers']['user-agent'] ) ) {
            $parsed_args['user-agent'] = $parsed_args['headers']['user-agent'];
            unset( $parsed_args['headers']['user-agent'] );
        }

        // Construct Cookie: header if any cookies are set.         WP_Http::buildCookieHeader( $parsed_args );

        $handle = curl_init();

        // cURL offers really easy proxy support.         $proxy = new WP_HTTP_Proxy();

        if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {

            curl_setopt( $handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP );
            curl_setopt( $handle, CURLOPT_PROXY, $proxy->host() );
            curl_setopt( $handle, CURLOPT_PROXYPORT, $proxy->port() );

            if ( $proxy->use_authentication() ) {
                
Home | Imprint | This part of the site doesn't use cookies.