今天调试一个非常老的代码时  发现nginx服务器超时  改了下nginx配置

发现是后台脚本一直等待  排查到最后发现是curl 超时引起的等待

具体解决方案:

curl_setopt( $this->ch, CURLOPT_URL, $url );
curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $this->ch, CURLOPT_TIMEOUT_MS,3000);      //  3秒超时
curl_setopt( $this->ch, CURLOPT_HEADER, 0 );
curl_setopt( $this->ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $this->ch, CURLOPT_SSL_VERIFYHOST, false );

PHP curl的超时主要有4个参数 原文如下;

There's a very distinctive difference between these two configurations within cURL. I'll try to define them for you, and then provide you a very common example which I share to people who I teach about cURL.

CURLOPT_CONNECTTIMEOUT is designed to tell the script how long to wait to make a successful connection to the server before starting to buffer the output. A destination's server which may be overloaded, offline or crashed would probably make this setting become useful.

CURLOPT_TIMEOUT is designed to tell the script how long to wait to receive a completely buffered output from the server. A destination's huge file, slow connection speeds or slow rendering would probably make this setting become useful.

A good example of where these will both apply to, is when you're telling cURL to download a MP3 file. CURLOPT_CONNECTTIMEOUT would be set at about 10 seconds which would mean that if no response is provided within 10 seconds then the script will abort, and CURLOPT_TIMEOUT would be set at about 100 seconds which would mean if the MP3 has not downloaded within 100 seconds then abort the script. It's the best way of explaining it to developers.

具体是:

CURLOPT_CONNECTTIMEOUT 

     建立连接时候的超时设置

  CURLOPT_TIMEOUT 

     接收信息时的超时设置

   CURLOPT_CONNECTTIMEOUT_MS,   CURLOPT_TIMEOUT_MS 意思相同 只是超时单位为毫秒了。。。

PHP curl超时问题的更多相关文章

  1. 【ipv6惹的祸】curl 超时

    偶然发现 最近在公司日志平台 总是可以看到很多关于php curl的错误信息 Operation timed out after 0 milliseconds with 0 out of 0 byte ...

  2. CURL超时处理

    一般会设置一个超时时间1S,就是说如果php那边在1S内没有返回给urlserver的话就忽略掉该请求,及不阻塞等待返回了,直接处理下面的操作. 现在php那边有时候会卡,这样一卡就无法再1S内返回消 ...

  3. CURL超时时间设置

    一次完整的http请求,一般包含三个步骤: 通过DNS把域名解析成IP 通过IP地址连接到目标主机 获取目标主机数据(1.给目标主机输出http请求头,以\r\n\r\n结尾:2.获取目标主机传过来的 ...

  4. curl 超时设置<转>

    PHP cURL 的超时设置有两个 CURLOPT_CONNECTTIMEOUT 和 CURLOPT_TIMEOUT,他们的区别是: CURLOPT_CONNECTTIMEOUT 用来告诉 PHP 在 ...

  5. PHP cURL 超时设置 CURLOPT_CONNECTTIMEOUT 和 CURLOPT_TIMEOUT 的区别

    PHP cURL 的超时设置有两个 CURLOPT_CONNECTTIMEOUT 和 CURLOPT_TIMEOUT,他们的区别是: CURLOPT_CONNECTTIMEOUT 用来告诉 PHP 在 ...

  6. curl 超时问题解决

    curl -o /dev/null -s -w %{time_namelookup}---%{time_connect}---%{time_starttransfer}---%{time_total} ...

  7. php之curl设置超时实例

    本文实例讲述了php中curl超时设置方法.分享给大家供大家参考.具体实现方法如下: 访问HTTP方式很多,可以使用curl, socket, file_get_contents() 等方法. 在访问 ...

  8. 本地服务CURL请求本地另一个服务API返回超时/或无返回

    入职之后一直在忙,终于有时间整理一波最近踩到的坑. 起因: 项目是微服务架构,一个项目对外提供API,新的项目调用API获得数据.于是就在本地搭建了两个服务.配置了两个虚拟域名,指向两个项目,当然我本 ...

  9. 用curl做异步操作

    class CurlPost { /** * @desc curl 请求提交数组 * */ public function execute($method, $url, $fields = '', $ ...

随机推荐

  1. Android Studio导入System Library步骤

    转载请注明出处:http://www.cnblogs.com/cnwutianhao/p/6242170.html 请尊重知识产权!!!  同步更新到CSDN:http://blog.csdn.net ...

  2. fir.im Weekly - 从零开始创建 Android 新项目

    今年的 Google I/O 大会上,人工智能和虚拟现实的产品发布让我们对未来多了几分惊喜.对于开发者部分,Google 发布了 Android N 系统,感受最深的是全新的 Android Stud ...

  3. fir.im Weekly - 论个人技术影响力是如何炼成的

    每个圈子都有一群能力强且懂得经营自己的人,技术圈也是如此.本期 fir.im Weekly 一如往期精选了一些实用的 iOS,Android 开发工具和源码分享,还有一些关于程序员的成长 Tips 和 ...

  4. Workflow中InArgument与OutArgument区别

    序号 InArgument[In参数] OutArgument[Out参数] 1 可以用VS设计器在xaml中定义[In参数]  可以用VS设计器在xaml中定义[Out参数] 2 在xaml中定义的 ...

  5. IDE:Eclipse查看接口实现类快捷键

    1.打开接口类 2.双击接口名选中 3.Ctrl+T,打开接口实现类

  6. 安卓学习进程(2)Android开发环境的搭建

        本节将分为五个步骤来完成Android开发环境的部署. 第一步:安装JDK. 第二步:配置Windows上JDK的变量环境 . 第三步:下载安装Eclipse . 第四步:下载安装Androi ...

  7. javascript运算符——位运算符

    × 目录 [1]二进制 [2]非 [3]与[4]或[5]异或[6]左移[7]右移[8]>>>[9]应用 前面的话 位运算符是非常底层的运算,由于其很不直观,所以并不常用.但是,其速度 ...

  8. nyoj 925 国王的烦恼(最小生成树)

    /* 题意:N个城市中每两个城市有多条路径连接,可是因为路径存在的天数是有限的!以为某条路经不存在了 导致N个城市不能连通了,那么村名们就会抗议!问一共会有多少次抗议! 思路:最小生成树....我们用 ...

  9. python--基础学习(四)自然字符串、重复字符串、子字符串

    python系列均基于python3.4环境 1.自然字符串和重复字符串 代码示例: str1=r'hello \npython' str2='hello \npython' str3="h ...

  10. 再次用CodeIgniter实现简易blog

    天变冷了,人也变得懒了不少,由于工作的需要,最近一直在学习CodeIgniter(CI)框架的使用,没有系统的从PHP基本语法学起,在网上靠百度谷歌,东拼西凑的实现了一些简单的功能.所以,老PHPer ...