Created
March 24, 2014 10:12
-
-
Save zhoumengkang/9737626 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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