0

I'm using cron to run everyday script, which has to run 5 php-cli processes. I need them to use separate interfaces.

I have 5 devices, eth0, eth1, eth2, eth3, eth4.

How can I call php to make sure it uses only one of them?

It's running on Centos 6.6

michail_w
  • 113
  • 5
  • What do you mean by using interface? What is your process/script doing? – Khaled May 28 '15 at 12:31
  • My script downloads data using curl (called as class from PHP, not as command). When I run this script, it always uses eth0 to connect. I need something like: `php script.php --interface=eth0 && php script.php --interface=eth1` etc. – michail_w May 28 '15 at 12:34

2 Answers2

3

Here is a related post from stackoverflow.

You need to use function call like the following to set interface name or IP address.

curl_setopt($curlh, CURLOPT_INTERFACE, "xxx.xxx.xxx.xxx");
Khaled
  • 36,533
  • 8
  • 72
  • 99
2

Why do you want to use a different interface in each case? Unless you are benchmarking the interfaces and for some reason want to do that in php, then there is probably a better solution.

libcurl does implement this sort of functionality, but I'm not sure about php's binding for it. If it's not there, you could just use the curl command directly via a shell call. From the man page:

   --interface <name>
          Perform an operation using a specified interface. You can  enter
          interface  name,  IP address or host name. An example could look
          like:

           curl --interface eth0:1 http://www.netscape.com/

(Wow. netscape.com, eh? Noone's gone over that man page in a while).

mc0e
  • 5,866
  • 18
  • 31