时间:2021-07-01 10:21:17 帮助过:2人阅读
function fsockopen_test(){
$hostname = 'm.cn';
$url = '/test/1.php';
$fp = fsockopen($hostname, 80, $errno, $errstr, 5);
if (!$fp) {
echo "$errstr ($errno)";
return false;
}
stream_set_blocking($fp,0);//开启了手册上说的非阻塞模式
$header = "GET $url HTTP/1.1\r\n";
$header.="Host: $hostname\r\n";
$header.="Connection: Close\r\n\r\n";//长连接关闭
fwrite($fp, $header);
fclose($fp);
}
fsockopen_test();
sleep(6);通过浏览器控制台查看实际还是会等test/1.php执行完毕,这边才刷新。这是为什么呢?
$fp = fopen ( './data.txt' , 'w' );
fwrite ( $fp ,111);
fclose ( $fp );
echo date('Y-m-d H:i:s'), PHP_EOL;可以看到没有延时
fsockopen_test();
echo date('Y-m-d H:i:s'), PHP_EOL;