Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select outgoing ip for curl request

Tags:

php

curl

ip

I have a server with two different IPs. I need to send odd curl requests from first IP, and even from the second one. How can I select outgoing IP address?

My PHP script is something like this:

$curlh = curl_init($url); curl_setopt($curlh, CURLOPT_USERAGENT, $uagent); curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curlh); 

How can I do so?

like image 489
Sergey Avatar asked Mar 11 '10 14:03

Sergey


People also ask

Can I do a curl request to the same server?

yes you can request normally, but do not change url as a file in local.


1 Answers

You may want to try setting the CURLOPT_INTERFACE option:

curl_setopt($curlh, CURLOPT_INTERFACE, "xxx.xxx.xxx.xxx"); 

CURLOPT_INTERFACE: The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name.

From: php Manual: curl_setopt


EDIT: Fixing example, as @Michael Hart pointed out pointed out in the other answer.

like image 52
Daniel Vassallo Avatar answered Sep 20 '22 07:09

Daniel Vassallo