Specify source ip using fsockopen

前端 未结 2 428
难免孤独
难免孤独 2020-12-20 22:27

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 fw

相关标签:
2条回答
  • 2020-12-20 23:00

    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);
    
    0 讨论(0)
  • 2020-12-20 23:09

    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 讨论(0)
提交回复
热议问题