php 异步调用

使用fsockopen 异步

/**
 * 异步调用方法
 * @version 1.0.0
 * @desc    异步运行url地址方法
 * @param   [string]          $url [url地址 支持get参数]
 * @param debug bool  true 测试异步回调是否执行  fals 不测试
 */
function SyncJob($url, $port = 80, $time = 30,$debug = false)
{
    $url_str = str_replace(array('http://', 'https://'), '', $url);
    $location = strpos($url_str, '/');
    $host = substr($url_str, 0, $location);
    $fp = fsockopen($host, $port, $errno, $errstr, $time);
    if($fp)
    {
        $out = "GET ".str_replace($host, '', $url_str)." HTTP/1.1\r\n";
        $out .= "Host: ".$host."\r\n";
        $out .= "Content-type: application/x-www-form-urlencoded\r\n";
        $out .= "Connection: Close\r\n\r\n";
        fputs($fp, $out);
        if($debug){
            $somecontent=date("Y-m-d H:i:s");
            $somecontent.="\r\n";
            $handle = fopen("2.txt", 'a');//创建文本,里面或有时间
            fwrite($handle, $somecontent);
            fclose($handle);
        }
        fclose($fp);
    }

}


//异步执行  程序会继续往下执行;
SyncJob('www.cbjdhd.com/qq/PHPMailer.php');//发送邮箱
echo json_encode(array('code'=>0,'msg'=>'发送成功!','data'=>array()));
exit();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值