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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With