doudiao2335 2019-01-01 07: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 08: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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失