$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文件确实是异步的执行了。

相关文章:

  • 2022-12-23
  • 2021-05-29
  • 2021-10-14
  • 2021-10-19
  • 2022-12-23
猜你喜欢
  • 2021-11-19
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案