```php class Tool{ //发送一个异步请求,忽略返回结果 public static function asyncPost($url,$params=[]){ $args = parse_url($url); //对url 进行处理 $host = $args['host']; //获取上报域名 $path = $args['path'].'?'.http_build_query($params); // 获取上报地址 if($args['scheme'] == 'https'){ //判断是否使用https $transports = 'ssl://'; //如果使用https则使用ssl协议 $port = !empty($args['port']) ? $args['port'] : 443; //如果使用https协议则使用443 }else{ $transports = 'tcp://'; //如果没有使用https则使用tcp; $port = !empty($args['port']) ? $args['port'] : 80;//如果使用https协议则使用80 } //使用fsocketopen打开一个socket通道,返回一个文件句柄,通过fwrite()往这个连接写入通讯信息 $fp = fsockopen($transports.$host,$port,$error_code,$error_msg,1); if(!$fp){ return false; }else{ stream_set_blocking($fp,true); //设置为阻塞模式 stream_set_timeout($fp,1); //避免出现超时30s的致命错误 $header = "GET $path HTTP/1.1\r\n"; $header .= "Host: $host\r\n"; $header .= "Connection: close\r\n\r\n"; fwrite($fp,$header); usleep(1000); fclose($fp); } } } ```