PHP异步调用socket

 1 <?
2 $host = "www.aaa.com";
3 $path = "/Report.php?ReportID=1";
4 $cookie = Session_id();
5
6 $fp = fsockopen($host, 80, $errno, $errstr, 30);
7 if (!$fp) {
8 print "$errstr ($errno)<br />\n";
9 exit;
10 }
11 $out = "GET ".$path." HTTP/1.1\r\n";
12 $out .= "Host: ".$host."\r\n";
13 $out .= "Connection: Close\r\n";
14 $out .= "Cookie: ".$cookie."\r\n\r\n";
15
16 fwrite($fp, $out); //将请求写入socket
17 //也可以选择获取server端的响应
18 /*while (!feof($fp)) {
19 echo fgets($fp, 128);
20 }*/
21 //如果不等待server端响应直接关闭socket即可
22 fclose($fp);
23 ?>
posted @ 2012-01-11 11:51  bluepace  阅读(682)  评论(0编辑  收藏  举报