views:

96

answers:

3

Hello, I have a Linux server with multiple ips (so, multiple eth0, eth0:0, eth0:1 etc). The script I'm trying to start is a php CLI script which is downloading stuff from an another server API, and I would like to change the IP based on different parameters. Once the script is started, I don't need anymore to change the ip OF THAT SPECIFIC script until his end.

Do you have any clue if it is possible to achieve it? My other solution was to install Xen or OpenVZ and create N different VPS per each IP, but as you can see is definitely a PITA :-)

+2  A: 

You don't specify how you connect to the other server, but with sockets you can try socket_bind.

EDIT: With curl you can try curl_setopt. CURLOPT_INTERFACE The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name.

OIS
O my god, you saved my day :-) I'll test it right now
Lucacri
A: 

I know how to do it in C - you use bind() on your socket before you call connect(), and you bind to the IP address assigned to the desired interface, passing 0 for port. I don't know how to do it in PHP.

Arkadiy
like socket_bind? :P
OIS
A: 

I connect using cURL and the service is a normal SOAP API over the port 80.

Using socket_bind looks like a lot of work...

Do you guys know if there is something like a wrapper application for linux? It would be great to do like "./use_network_1 /usr/bin/php myapp.php"...

Lucacri