Reputation:
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
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