Skip to content

Instantly share code, notes, and snippets.

@zhoumengkang
Created March 24, 2014 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhoumengkang/9737626 to your computer and use it in GitHub Desktop.
Save zhoumengkang/9737626 to your computer and use it in GitHub Desktop.
function fsockopen_test(){
$hostname = 'm.cn';
$url = '/bbb/2.php';
$fp = fsockopen($hostname, 80, $errno, $errstr, 5);
if (!$fp) {
echo "$errstr ($errno)";
return false;
}
$header = "GET $url HTTP/1.1\r\n";
$header.="Host: $hostname\r\n";
$header.="Connection: Close\r\n\r\n";//长连接关闭
fwrite($fp, $header);
/*$html = '';
while (!feof($fp)) {
$html.=fgets($fp);
}
echo $html;*/
//如果上面这段代码不注释,还是会对$fp进行读取,所以还是会阻塞,所以类似的问题,我们要注意
fclose($fp);
}
echo time(),'<br>';
fsockopen_test();
echo time(),'<br>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment