Home >Backend Development >PHP Tutorial >聊好的fsockopen的非阻塞模式呢?为什么还是会阻塞

聊好的fsockopen的非阻塞模式呢?为什么还是会阻塞

WBOY
WBOYOriginal
2016-06-13 11:52:191211browse

说好的fsockopen的非阻塞模式呢?为什么还是会阻塞

function fsockopen_test(){<br />    $hostname = 'm.cn';<br />    $url = '/test/1.php';<br />    $fp = fsockopen($hostname, 80, $errno, $errstr, 5);<br />    if (!$fp) {<br />        echo "$errstr ($errno)";<br />        return false;<br />    }<br />    stream_set_blocking($fp,0);//开启了手册上说的非阻塞模式<br />    $header = "GET $url HTTP/1.1\r\n"; <br />    $header.="Host: $hostname\r\n";<br />    $header.="Connection: Close\r\n\r\n";//长连接关闭<br />    fwrite($fp, $header);<br />    fclose($fp);<br />}<br />fsockopen_test();

请求的/test/1.php里面的代码:
sleep(6);<br />$fp  =  fopen ( './data.txt' ,  'w' );<br />fwrite ( $fp ,111);<br />fclose ( $fp );
通过浏览器控制台查看实际还是会等test/1.php执行完毕,这边才刷新。这是为什么呢?
------解决方案--------------------
没问题呀
echo date('Y-m-d H:i:s'), PHP_EOL;<br />fsockopen_test();<br />echo date('Y-m-d H:i:s'), PHP_EOL;<br />
可以看到没有延时

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn