fsockopen发送异步请求 GET POST 封装函数
1 //fsockopen发送异步请求 GET POST 2 function fssend($path,$data=[],$post=false){ 3 $host = request()->host(); 4 $data = http_build_query($data); 5 $len = strlen($data); 6 $fp = fsockopen( $host , 80, $errno, $errstr, 3); 7 if ($fp) { 8 if ($post){ 9 $header = "POST $path HTTP/1.1\r\n"; 10 $header .= "Host: $host\r\n"; 11 $header .= "Content-type: application/x-www-form-urlencoded\r\n"; 12 $header .= "Connection: Close\r\n"; 13 $header .= "Content-Length: $len\r\n"; 14 $header .= "\r\n"; 15 $header .= $data."\r\n"; 16 }else{ 17 $header = "GET $path?$data HTTP/1.1\r\n"; 18 $header .= "Host: $host\r\n"; 19 $header .= "\r\n"; 20 } 21 fwrite($fp, $header); 22 fclose($fp); 23 } 24 }
灵感来源:https://www.jb51.net/article/72569.htm

浙公网安备 33010602011771号