php异步函数执行

来源:互联网 发布:阿里云 物理专线 编辑:程序博客网 时间:2024/06/05 04:32

//实现功能主要的函数

public function send($url){

        $url_array = parse_url($url);
        $hostname = $url_array['host'];
        $port = isset($url_array['port'])? $url_array['port'] : 80;
        $requestPath = $url_array['path'] ."?". $url_array['query'];
        $fp = fsockopen($hostname, $port, $errno, $errstr, 10);
        if (!$fp) {
            echo "$errstr ($errno)";
            return false;
        }
        $method = "GET";
        if(!empty($post_data)){
            $method = "POST";
        }
        $header = "$method $requestPath HTTP/1.1\r\n";
        $header.="Host: $hostname\r\n";
        if(!empty($post_data)){
            $_post = strval(NULL);
            foreach($post_data as $k => $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);

        fclose($fp);

}

//函数1里面需要执行函数2,执行到函数2的时候,不用等函数2执行完成,继续执行函数1


//函数1

public function order_taking(){
//函数1的执行函数
        ignore_user_abort(true); // 忽略客户端断开
        set_time_limit(0);       // 设置执行不超时

//函数2的地址
        $url = ROOT_URL.'/Lawyer/send_take_order/id/'.$id.'('.session('zyuid');
        send($url); 

//函数1的执行函数
 }

//函数2

public function send_take_order(){
        //函数2的执行函数

}


0 0