在A请求页面发起另一个B页面请求 不需要等待B页面执行结束再返回 直接往下执行A页面的请求
A页面代码
<?php $url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/send.php"; $param = array( 'name'=>'fdipzone', 'gender'=>'male', 'age'=>30 ); doRequest($url, $param);//发起请求 function doRequest($url, $param=array()) { $urlinfo = parse_url($url); $host = $urlinfo['host']; $path = $urlinfo['path']; $query = isset($param)? http_build_query($param) : ''; $port = 80; $errno = 0; $errstr = ''; $timeout = 10; $fp = fsockopen($host, $port, $errno, $errstr, $timeout); $out = "POST ".$path." HTTP/1.1 "; $out .= "host:".$host." "; $out .= "content-length:".strlen($query)." "; $out .= "content-type:application/x-www-form-urlencoded "; $out .= "connection:close "; $out .= $query; fputs($fp, $out); fclose($fp); } ?>
B页面代码
<?php for($i=0;$i<10;$i++) { sleep(1); file_put_contents(time().".txt",time()); } ?>
然后效果如图:
然后逐步增加了新文件