TechniqueUse the fsockopen() function, which opens a socket to the specified server. Subsequently, you send to and retrieve information from that socket via the fgets() , fgetss() , and fputs() functions: <?php $sp = fsockopen($hostname, $port, &$errno, &$errstr, $timeout); if (!$sp) { print "$errstr [$errno]<br>\n"; } else { fputs($fp,"GET / HTTP/1.0\r\n\r\n"); while ($line = fgets($fp, 1024)) { print $line; } fclose($sp); } ?> CommentsThe fsockopen() function provides a simple API for using sockets. For more information on fsockopen() and some of PHP's more advanced socket features, see Chapter 14, "Communicating with Sockets." |