I have some functions that use stream_socket_client (not curl) in php and I have multiple eth1 eth2 ...etc interfaces with different ips So i want to use different interfaces when i connect as a client, can I do that? I can't find no option for that nor in php.ini
AFAIK that's not possible. Interfaces are abstracted away from PHP; you just get to use them, not choose them.
Edit: let me rephrase that. If you want to make a system/shell call (eg, ifconfig -a
) and parse that output, then bind the socket to that particular address, you may have luck... but it seems like iffy business.
-
As to how to bind to a particular address, see the socket context options – Artefacto Nov 11 '10 at 0:02
Here is how to add IP interface in stream_socket_client
// connect to the internet using the '192.168.0.100' IP
$opts = array(
'socket' => array(
'bindto' => '192.168.0.100:0',
),
);
// create the context...
$context = stream_context_create($opts);
$fp = @stream_socket_client ( $link, $errno, $errstr, 120, STREAM_CLIENT_CONNECT, $context);