php(tp5)异步请求接口

// $url接口地址
$url = 'http://域名/public/home/Index/compress_video';
// $post_data为参数
$post_data['path'] = ROOT_PATH . 'public/uploads/video/';
$post_data['video_url'] = $frm['video'];
$post_data['newsid'] = $result->newsid;
send_request($url, $post_data);


/**
 * 发起请求,不等待返回结果
 * @param  [type] $host 请求地址
 * @return [type] [description]
 */
function send_request($url, $data = array()) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_exec($ch);
    curl_close($ch);
}

猜你喜欢

转载自blog.csdn.net/qq_36611673/article/details/127264105