Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Ilia Alshanetsky's Blog:
PHP Bind Support (via streams)
Jun 15, 2005 @ 11:13:37

Ilia Alshanetsky has a quick new post over on his weblog today concerning "PHP bind support via stream context".

Up until a few days there was no way to tell PHP from which IP address to submit requests when making connections on a multi-ip server. PHP would automatically pick the 1st external IP and use it deliver external data. To address this limitation, I've added a context option that allows to you to bind an IP from the available local IPs and use it, rather then the default to initiate the connection.

The "socket" wrapper option "bindto" takes a ipv4 or ipv6 address as well as a port, binds the connection to it. Using the port is not necessary in most cases, if you simply wish to bind to a certain IP, specify it followed by ":0" as shown in the example.

Here's his sample: array('bindto' => "1.2.3.4:0"))); file_get_contents("http://url", NULL, $conn); ?>

tagged:

Link:


Trending Topics: