Reputation: 8880
I run several servers in the same data center that have internal networking enabled. In the interests of speed and costs (internal traffic is not billed) I would like to be able to cURL between the various servers on their internal IPs.
I have just discovered that if I attempt something along the lines of
curl_init('10.x.x.x);
or even
curl_init():
curl_setopt(CURLOPT_URL,'https://10.x.x.x/scripttorun.php');
does not work. When I have only a very small quantity of data to send out I can append it as a query string and do a file_get_contents. However, when the amount of data is too big to send out as a GET request things get messier if I cannot use cURL.
A spot of searching suggested that I could persuade cURL to use IPs by editing the /etc/hosts table. The problem is that the various servers on the internal network may go on and off line at unpredicatable intervals so I would end up having to poll regularly to see which servers are online, write a script to update /etc/hosts... which gets pretty messy.
Perhaps there is a simple solution that can persuade cURL to use IPs. After all, file_get/put_contents does so without flinching. I'd be most obliged to anyone who might be able workaround for cURL
Upvotes: 4
Views: 3824
Reputation: 359
If you ever have to connect to a server and ask for particular server name you can do it with curl setopt parameters. If you want to get file /index.php from www.mytopsite.com from particular IP (without adding any /etc/hosts mappings) you can do it like this:
$headers = array("Host: www.myfaketopsite.com");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, "http://10.1.2.3/index.php");
Upvotes: 3