thinkphp 异步访问耗时操作

/**
 * 耗时异步操作
 * @param $url   模板      模块名称/控制器/方法?参数名=参数值
 * */
function  asyncronous($url){
    if(empty($url)){
        return array("flag"=>false,"msg"=>"参数不正确");
    }
    if(strpos($url, "/")==0){
        return array("flag"=>false,"msg"=>"参数格式错误");
    }
    $server=$_SERVER['HTTP_HOST'];
    $fp = fsockopen($server,80,$errno,$errstr,5); 
        if(!$fp){
            return array("flag"=>false,"msg"=>"$errstr ($errno)");
         }
    $out = "GET /$url  / HTTP/1.1\r\n";
    $out .= "Host: $server\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
   //忽略执行结果
  //while (!feof($fp)) { echo fgets($fp, 128); }
    fclose($fp);
    return array("flag"=>true,"msg"=>"异步调用成功!");
}

你可能感兴趣的:(php)