關於php curl逾時問題

來源:互聯網
上載者:User
我用curl寫了一個get擷取返回狀態的代碼
function http_get_code($url){    $curl = curl_init();    curl_setopt($curl, CURLOPT_URL, $url);    curl_setopt($curl, CURLOPT_HEADER, 1);    curl_setopt($curl, CURLOPT_TIMEOUT,60);     curl_setopt($curl,CURLOPT_NOBODY,true);    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);    $data = curl_exec($curl);    $recode=curl_getinfo($curl,CURLINFO_HTTP_CODE);    curl_close($curl);    return $recode;}

明明設定了逾時為1秒,但是有個不開放80連接埠的網址運行到curl_exec處還是報Maximum execution time of 30 seconds exceeded in錯誤為什嗎?


回複討論(解決方案)

http://blog.csdn.net/henriezhang/article/details/38308413

明明是 curl_setopt($curl, CURLOPT_TIMEOUT, 60);
怎麼能說 1 秒,說一分鐘才對

curl_setopt($curl, CURLOPT_TIMEOUT,60);

你設定的是60秒,一分鐘。

你的問題時伺服器設定了php最大執行時間時30秒,可以用以下語句修改
在php檔案中,加入
ini_set('max_execution_time', '300'); 改為300秒

或修改php.ini
max_execution_time = 300

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.