doudiao2335 2018-12-31 23:51
浏览 224
已采纳

cURL不再工作,给出408错误

I have a cURL code which was working before but recently it stopped working and gives a 408 request timeout error. I want to know the reason why it stopped working and how can I fix it. Here's the code :

$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $header);
curl_setopt($curlSession, CURLOPT_URL, $actualUrl); 
curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlSession, CURLOPT_POST, 0);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlSession, CURLOPT_TIMEOUT,1100);
curl_setopt($curlSession, CURLOPT_SSLCERT, $clientcert); 
curl_setopt($curlSession, CURLOPT_SSLCERTTYPE, 'PEM'); 
curl_setopt($curlSession, CURLOPT_SSLKEYTYPE, 'PEM'); 
curl_setopt($curlSession, CURLOPT_SSLKEY, $keyfile); 
curl_setopt($curlSession, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curlSession, CURLOPT_USERAGENT, $agent);
$data = curl_exec($curlSession);

I tried it with the Postman application and it still works on Postman without any delay.Is there any alternative to cURL that I can use to check this?

  • 写回答

1条回答 默认 最新

  • douyun3799 2019-01-01 00:05
    关注

    The 408 Request Timeout error is an HTTP status code that means the request you sent to the website server (e.g. a request to load a web page) took longer than the website's server was prepared to wait. In other words, your connection with the website "timed out."

    You can test your API with postman first to see whether it is working fine.

    Is your api return large amount of data or your remote server is slow resulting a long request-response time?

    See documentation: http://www.php.net/manual/en/function.curl-setopt.php

    CURLOPT_CONNECTTIMEOUT - The number of seconds to wait while trying to connect. Use 0 to wait indefinitely. URLOPT_TIMEOUT - The maximum number of seconds to allow cURL functions to execute.

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds
    

    also don't forget to enlarge time execution of php script if needed.

    set_time_limit(0);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部