https_request請求接口返回數據


定義一個https_request方法

<?php
function https_request($url, $data = null,$time_out=60,$out_level="s",$headers=array())
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_NOSIGNAL, 1);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    if($out_level=="s")
    {
        //超時以秒設置
        curl_setopt($curl, CURLOPT_TIMEOUT,$time_out);//設置超時時間
    }elseif ($out_level=="ms") 
    {
        curl_setopt($curl, CURLOPT_TIMEOUT_MS,$time_out);  //超時毫秒,curl 7.16.2中被加入。從PHP 5.2.3起可使用 
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    if($headers)
    {
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);//如果有header頭 就發送header頭信息
    }
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}
?>

 

如果想用毫秒級超時 需要先看看curl版本  用phpinfo函數跑一下就行了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM