You may think connecting to another Internet server is difficult but you would be wrong. You can establish a connection in just one line of PHP code. In this section I will show you how to simply connect and disconnect using sockets.
<?php /* Arguments that fsockopen takes: fsockopen(Hostname/IP, Port Number, Error Number Variable, Error Description Variable) The error number variable and error description variable are populated only on failure of fsockopen. $errno will contain the error number and $errdesc will contain the error description e.g. Server cannot be found. */ $fp = fsockopen( "www.example.com", 80, $errno, $errdesc); ?>
Now that we have established a connection to the server at example.com let's close the connection. You might be familiar with the fclose() function, we use this to close the connection.