//异步请求函数(用debug参数若为true则为用为调试,开启调试可以看到异步的执行情况,但是失去异步的效果)
main.php
$v){ $_post[]= $k."=".urlencode($v);//必须做url转码以防模拟post提交的数据中有&符而导致post参数键值对紊乱 } $_post = implode('&', $_post); $header .= "Content-Type: application/x-www-form-urlencoded\r\n";//POST数据 $header .= "Content-Length: ". strlen($_post) ."\r\n";//POST数据的长度 $header.="Connection: Close\r\n\r\n";//长连接关闭 $header .= $_post; //传递POST数据 }else{ $header.="Connection: Close\r\n\r\n";//长连接关闭 } fwrite($fp, $header); //-----------------调试代码区间----------------- //注如果开启下面的注释,异步将不生效可是方便调试 if($debug){ $html = ''; while (!feof($fp)) { $html.=fgets($fp); } echo $html; } //-----------------调试代码区间----------------- fclose($fp); } $data=array('name'=>'guoyu','pwd'=>'123456'); $url='http://localhost/test/other.php'; request_by_fsockopen($url,$data,true);//
other.php
使用实例:
已抢66461个
抢已抢37089个
抢已抢20553个
抢已抢2531个
抢已抢18985个
抢