Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl --resolve equivalent in PHP CURL library

Tags:

http

php

curl

ssl

Is there an equivalent for curl --resolve .... in PHP CURL library ?

Background: I have round-robin DNS (one domain name resolves to multiple IPs), and I want to send a request to a specific host. I use apache name-based virtual hosts, and thus a correct domain name must appear in the HTTP request.

I have tried specifying the IP in the request URL: curl_setopt($ch, CURLOPT_URL, '127.0.0.1'), and using curl_setopt($ch, CURLOPT_HTTPHEADER, 'Host: example.com'). It works for HTTP, but for HTTPS I get SSL verification error (apparently CURL verifies certificate vs. URL hostname and NOT Host: hostname).

Using hosts file is not a convenient option.

like image 623
Sandman4 Avatar asked May 03 '12 14:05

Sandman4


People also ask

How does PHP handle cURL request?

PHP cURL GET request In the example, we send a GET request to a small website. The output is directly shown in the standard output. $ch = curl_init('http://webcode.me'); The curl_init function initializes a new session and returns a cURL handle for use with the curl_setopt , curl_exec , and curl_close functions.

Which is faster cURL or file_get_contents?

This is old topic but on my last test on one my API, cURL is faster and more stable. Sometimes file_get_contents on larger request need over 5 seconds when cURL need only from 1.4 to 1.9 seconds what is double faster.

What is the use of Curlopt_returntransfer?

Returns true on success or false on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, false on failure. This function may return Boolean false , but may also return a non-Boolean value which evaluates to false . Please read the section on Booleans for more information.


1 Answers

First, the best way to get an answer to how any curl option translates to libcurl (or PHP/CURL) is by using the --libcurl option.

If you do, you will learn that --resolve translates to CURLOPT_RESOLVE with libcurl, supported in PHP since 5.5.0. Supported by libcurl since 7.21.3.

like image 175
Daniel Stenberg Avatar answered Sep 18 '22 11:09

Daniel Stenberg