Open socket and read : Socket « Network « PHP

Open socket and read

   // Establish a port 80 connection with
   $http = fsockopen("",80);

   // Send a request to the server
   $req = "GET / HTTP/1.1\r\n";
   $req .= "Host:\r\n";
   $req .= "Connection: Close\r\n\r\n";
   fputs($http, $req);

   // Output the request results
   while(!feof($http)) {
      echo fgets($http, 1024);

   // Close the connection



Related examples in the same category

1.Getting and Printing a Web Page with fopen()
2.Outputting the Status Lines Returned by Web Servers
3.Retrieving a Web Page Using fsockopen()