How to open and read socket in PHP

1 Answer

0 votes
$http = fsockopen("www.seek4info.com", 80);

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

while (!feof($http)) 
  echo fgets($http, 1024);

fclose($http);
 
/*
run:
 
HTTP/1.1 200 OK
X-Powered-By: PHP/5.4.45
Set-Cookie: ...; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Type: text/html
Transfer-Encoding: chunked
Date: Fri, 07 Oct 2016 16:01:45 GMT
Accept-Ranges: bytes
Server: Lite...Speed
Connection: close

2000

<!doctype html>
<html>
    <head>
        <title>Seek.4Info - Relevant Search Engine</title>  
        ...
 
*/

 



answered Oct 7, 2016 by avibootz

Related questions

...