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.
I have a solution to this with the help of Python.
In the .php file, just echo the output of python:
In python.py:
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 are going to bother to fork another process, just fork curl itself with the "--resolve" option versus yet another script.