functionHttp_request ($url,$method= ' GET ',$postfields=NULL,$headers=Array()) { $parse=Parse_url($url); isset($parse[' Host ']) ||$parse[' host '] = '; isset($parse[' Path ']) ||$parse[' path '] = '; isset($parse[' Query ']) ||$parse[' query '] = '; isset($parse[' Port ']) ||$parse[' port '] = '; $path=$parse[' Path ']?$parse[' Path ']. ($parse[' Query ']? ‘?‘.$parse[' Query ']: '): '/'; $host=$parse[' Host ']; //Protocol if($parse[' scheme '] = = ' HTTPS ') { $version= ' 1.1 '; $port=Empty($parse[' Port ']) ? 443:$parse[' Port ']; $host= ' ssl://'.$host; } Else { $version= ' 1.0 '; $port=Empty($parse[' Port ']) ? 80:$parse[' Port ']; } //Headers $headers[] = "Host: {$parse[' Host ']} "; $headers[] = ' connection:close '; $headers[] = "User-agent:$_server[Http_user_agent] "; $headers[] = ' Accept: */* '; //Package Body Information if($method= = ' POST ') { if(Is_array($postfields)){ $postfields=Http_build_query($postfields); } $headers[] = "content-type:application/x-www-form-urlencoded"; $headers[] = ' content-length: '.strlen($postfields); $out= "POST$pathhttp/$version\ r \ n ".Join("\ r \ n",$headers)." \r\n\r\n ".$postfields; } Else { $out= "GET$pathhttp/$version\ r \ n ".Join("\ r \ n",$headers)." \r\n\r\n "; } //Send Request $limit= 0; $fp=Fsockopen($host,$port,$errno,$errstr, 30); if(!$fp) { Exit(' Failed to establish socket connection: '.$url); } Else { $header=$content= ' '; //Set block/nonblocking mode stream, $block ==true apply flow mode stream_set_blocking($fp,true); //to set the time-out for a stream Stream_set_timeout($fp, 30); fwrite($fp,$out); //Get Header/metadata from the encapsulated protocol file pointer $status=Stream_get_meta_data($fp); if(!$status[' Timed_out ']) {//not timed out while(!feof($fp)) { $header.=$h=fgets($fp); if($h&& ($h= = "\ r \ n" | |$h= = "\ n")) Break; if(Strpos($h, ' content-length: ')!==false) { $limit=intval(substr($header, 15)); } } $stop=false; while(!feof($fp) &&!$stop) { $data=fread($fp, ($limit= = 0 | |$limit> 8192? 8192:$limit)); $content.=$data; if($limit) { $limit-=strlen($data); $stop=$limit<= 0; } } } fclose($fp); //Unchunk $content=Preg_replace_callback( ‘/(?:(?:\ r\n|\n) |^) ([0-9a-f]+) (?: \ r\n|\n) {. *?) '. ‘((?:\ r\n|\n) (?: [0-9a-f]+ (?: \ r\n|\n) |$)/si ',create_function( ' $matches ', ' Return Hexdec ($matches [1]) = = strlen ($matches [2])? $matches [2]: $matches [0]; ' ),$content ); return $content; }}
Execute the script asynchronously by adding the following code:
Ignore_user_abort (TRUE);//If the client disconnects, it will not cause script abortset_time_limit (0);//Cancel script execution delay limit
Fsockopen Get,post Package (RPM)