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

报告相同问题?

悬赏问题

  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致