![php异步请求(可以做伪线程) php异步请求(可以做伪线程)](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
$fp = fsockopen("www.baidu.com", 80, $errno, $errstr, 30);
stream_set_blocking($fp,0); // 设置成非阻塞请求
if (!$fp) die('error fsockopen');
$http = "GET /yibu/yibu.php / HTTP/1.1\r\n";
$http .= "Host: www.baidu.com\r\n";
$http .= "Connection: Close\r\n\r\n";
fwrite($fp,$http);
fclose($fp);
这样利用fsockopen来做php的异步操作,有缺点,可能是因为需要建立连接和关闭连接的时间,而这段时间取决与请求的服务器和被请求的服务器的网络状况,是fsockopen所解决不了的问题,这也是弊端,而被请求的php文件确实是异步的执行了。