fsockopen() function establishes a socket connection, TCP or UDP. : fsockopen « File Directory « PHP






fsockopen() function establishes a socket connection, TCP or UDP.

 
Its syntax is: int fsockopen (string host, int port [, int errnumber [, string errstring [, int timeout]]])

errnumber and errstring return error information specific to the attempt to connect to the host. 

<?
function get_the_host($host,$path) {
     $fp = fsockopen($host, 80, &$errno, &$errstr, 30);
     socket_set_blocking($fp, 1);
     fputs($fp,"GET $path HTTP/1.1\r\n");
     fputs($fp,"Host: $host\r\n\r\n");
     $x = 1;
     while($x < 10) :
          $headers = fgets($fp, 4096);
          print $headers;
          $x++;
     endwhile;
     fclose($fp);
}

get_the_host("www.java2s.com", "/");
?>
  
  








Related examples in the same category

1.Outputting the Status Lines Returned by Web Servers
2.fsockopen.php
3.SSL Streams
4.Sockets Are Files
5.Scan a server
6.Retrieving a Web Page Using fsockopen()