php异步函数执行

//实现功能主要的函数

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的执行函数

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值