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)
The function stream_socket_client() is similar but provides a richer set of options, including non-blocking connection and the ability to provide a stream context.
This sample code checks to see if the fsockopen() function is available. To check for another function, change the $function_name variable's value: <? php $function_name = "fsockopen"; if ( function_exists($function_name ) ) { echo "$function_name is enabled"; } else { echo "$function_name is not enabled"; } ?>
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With