开发者

Specify source ip using fsockopen

开发者 https://www.devze.com 2023-02-06 06:25 出处:网络
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

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().

0

精彩评论

暂无评论...
验证码 换一张
取 消