两个文件:(1)brief.php主程序文件(2)doRequest.php需要异步处理的程序
brief.php:
$url = 'localhost:8867'; echo 123; // 先输出,中间部分为异步处理程序 $fp = fsockopen($url,-1, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br /> "; } else { $out = "GET /doRequest.php HTTP/1.1 "; $out .= "Host: ".$url." "; $out .= "Connection: Close "; //stream_set_blocking($fp,true); //stream_set_timeout($fp,1); fwrite($fp, $out); usleep(1000); fclose($fp); } echo 4567;
doRequest.php:
echo 123; $param = ['$_GET', '$_POST']; sleep(2); file_put_contents('./dorequest.txt', var_export($param, true), FILE_APPEND);