Specify source ip using fsockopen
On a server with multiple IPs routed to it, I'd like to use PHP's fsockopen to open from a non-primary-interface ip (or a comparable method to be able开发者_如何学运维 to make fread and fwrites from a different ip)
This is not possible with fsockopen
. You have to use the sockets wrapper:
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($sock, '192.168.1.100');
socket_connect($sock, 'stackoverflow.com', 80);
With the standard arguments offered, it may not be possible.
This article (see: http://bytes.com/topic/php/answers/568317-specify-source-address-interface-use-when-using-fsockopen) suggests that you have to go down a level and use socket_bind().
精彩评论