5

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)

7

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);
1
  • since fread(): supplied resource is not a valid stream resource, are there similar (easy) ways to read and write to that socket? – Professional Sounding Name Jan 22 '11 at 1:21
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.