user1644380
user1644380

Reputation:

If my server has multiple IP addresses, how can I run a script using each of the IP addresses?

Let's say my server has 10 IP addresses.

I'd like to run the same PHP script 10 times, but each time use a different one of the IP addresses. The PHP script would be accessing the internet.

Is something like this possible? (using a different IP each time)

If so, can you point me in the right direction of being able to do this?

Thank you.

Upvotes: 5

Views: 1906

Answers (1)

Jonathan M
Jonathan M

Reputation: 17451

You can choose which interface you bind to:

$options = array(
    'socket' => array(
        'bindto' => '192.168.0.12:0',
     ),
);

$context = stream_context_create($options);

/* Sends an http request to www.example.com through local interface 192.168.0.12:0 */
$fp = fopen('http://www.example.com', 'r', false, $context);
fpassthru($fp);
fclose($fp);

http://php.net/manual/en/function.stream-context-create.php

Upvotes: 4

Related Questions