PHP curl超时问题
今天调试一个非常老的代码时 发现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超时问题的更多相关文章
- 【ipv6惹的祸】curl 超时
偶然发现 最近在公司日志平台 总是可以看到很多关于php curl的错误信息 Operation timed out after 0 milliseconds with 0 out of 0 byte ...
- CURL超时处理
一般会设置一个超时时间1S,就是说如果php那边在1S内没有返回给urlserver的话就忽略掉该请求,及不阻塞等待返回了,直接处理下面的操作. 现在php那边有时候会卡,这样一卡就无法再1S内返回消 ...
- CURL超时时间设置
一次完整的http请求,一般包含三个步骤: 通过DNS把域名解析成IP 通过IP地址连接到目标主机 获取目标主机数据(1.给目标主机输出http请求头,以\r\n\r\n结尾:2.获取目标主机传过来的 ...
- curl 超时设置<转>
PHP cURL 的超时设置有两个 CURLOPT_CONNECTTIMEOUT 和 CURLOPT_TIMEOUT,他们的区别是: CURLOPT_CONNECTTIMEOUT 用来告诉 PHP 在 ...
- PHP cURL 超时设置 CURLOPT_CONNECTTIMEOUT 和 CURLOPT_TIMEOUT 的区别
PHP cURL 的超时设置有两个 CURLOPT_CONNECTTIMEOUT 和 CURLOPT_TIMEOUT,他们的区别是: CURLOPT_CONNECTTIMEOUT 用来告诉 PHP 在 ...
- curl 超时问题解决
curl -o /dev/null -s -w %{time_namelookup}---%{time_connect}---%{time_starttransfer}---%{time_total} ...
- php之curl设置超时实例
本文实例讲述了php中curl超时设置方法.分享给大家供大家参考.具体实现方法如下: 访问HTTP方式很多,可以使用curl, socket, file_get_contents() 等方法. 在访问 ...
- 本地服务CURL请求本地另一个服务API返回超时/或无返回
入职之后一直在忙,终于有时间整理一波最近踩到的坑. 起因: 项目是微服务架构,一个项目对外提供API,新的项目调用API获得数据.于是就在本地搭建了两个服务.配置了两个虚拟域名,指向两个项目,当然我本 ...
- 用curl做异步操作
class CurlPost { /** * @desc curl 请求提交数组 * */ public function execute($method, $url, $fields = '', $ ...
随机推荐
- 学习ASP.NET MVC(七)——我的第一个ASP.NET MVC 查询页面
在本篇文章中,我将添加一个新的查询页面(SearchIndex),可以按书籍的种类或名称来进行查询.这个新页面的网址是http://localhost:36878/Book/ SearchIndex. ...
- MongoDB修改器的使用1
为什么要使用修改器? 通常我们只会修改文档的一部分,这时候更新整个文档就显得很麻烦,通常是通过原子性的更新修改器来完成. 1."$set"修改器 "$set ...
- VS报错:_CRT_SECURE_NO_WARNINGS
常见报错:warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead ...
- java基础复习 - 自动装箱
Integer a = 127; // 将整形127装箱对象 Integer b = 127; // 同上 System.out.print( a==b ); // true System.out.p ...
- 深入理解javascript作用域系列第四篇——块作用域
× 目录 [1]let [2]const [3]try 前面的话 尽管函数作用域是最常见的作用域单元,也是现行大多数javascript最普遍的设计方法,但其他类型的作用域单元也是存在的,并且通过使用 ...
- javascript中Date对象的应用——简易日历的实现
× 目录 [1]效果 [2]HTML [3]CSS[4]JS 前面的话 简易日历作为javascript中Date对象的常见应用,用途较广泛.本文将详细说明简易日历的实现思路 效果演示 HTML说明 ...
- PHP Log时时查看小工具
以前Log都是打印在一个文档中,然后打开文件夹,最后打开文档查看里面的内容,每次打开文件夹感觉很烦. 前些日子看到同事开发.NET的时候,用他自己的一个小工具能够时时查看到Log的内容,非常方便,所以 ...
- H5游戏开发之Stick Hero
自从上次发布一个小恐龙游戏以后,到现在10天了,前后又写了3个游戏,挑了一个感觉比较有挑战的游戏和大家分享一下. 效果演示 这是我模拟一个苹果游戏<stick hero>游戏写的一个小游戏 ...
- Greenplum测试环境部署
1.准备3台主机 本实例是部署实验环境,采用的是Citrix的虚拟化环境,分配了3台RHEL6.4的主机. |------|------| |Master|创建模板后,额外添加20G一块磁盘/dev/ ...
- URL格式
URL由三部分组成:资源类型.存放资源的主机域名.资源文件名. URL的一般语法格式为: (带方括号[]的为可选项): protocol :// hostname[:port] / path / [; ...