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 = '', $ ...
随机推荐
- CCNA网络工程师学习进程(6)vlan相关协议的配置与路由器简单配置介绍
前面已经介绍了大部分与vlan技术相关的交换机的协议的配置,更深层次的还有STP协议和以太网端口聚合技术,接着还会简单介绍一下路由器的基本应用. (1)STP(Spanning-tre ...
- ::after::before清除浮动原理
先来看一段代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- Android属性动画之第一重修炼总结
经过这两天对ObjectAnimator属性动画的学习,基本对Android提供的属性动画有了一定的认识,现在就为大家以一个类似扇形打开的效果做总结. 效果图: 下面就让我们用刚刚学到的属性动画效果, ...
- SharePoint Server 2013开发之旅(三):为SharePoint Server配置App开发、部署、管理环境
上一篇我讲解了如何利用微软提供的Office 365开发人员网站,进行在线的SharePoint App开发,这当然是不错的一个选择,因为你可以快速地进行开发和调试.(仅仅针对App开发而言).但是, ...
- Java多线程系列--“JUC集合”09之 LinkedBlockingDeque
概要 本章介绍JUC包中的LinkedBlockingDeque.内容包括:LinkedBlockingDeque介绍LinkedBlockingDeque原理和数据结构LinkedBlockingD ...
- 轻松自动化---selenium-webdriver(python) (四)
本节要解决的问题: 如何定位一组元素? 场景 从上一节的例子中可以看出,webdriver可以很方便的使用findElement方法来定位某个特定的对象,不过有时候我们却需要定位一组对象, 这时候就需 ...
- 【LeetCode】Self Crossing(335)
1. Description You are given an array x of n positive numbers. You start at point (0,0) and moves x[ ...
- PhoneGap在iOS开发下的注意事项
敏捷个人应用主要是在Andorid下开发,发布的也主要是Andorid.之所以没有急着退出iOS版本,主要是因为开发iOS需要iOS的开发环境,发布还需要开发者账号,这些都需要资源或钱.而最近越来越多 ...
- CSS魔法堂:你一定误解过的Normal flow
前言 刚接触CSS时经常听到看到一个词"文档流",那到底什么是"文档流"呢?然后会看到"绝对定位和浮动定位能脱离文档流",从这句可以看到文 ...
- JS魔法堂:LINK元素深入详解
一.前言 我们一般使用方式为 <link type="text/css" rel="stylesheet" href="text.css&quo ...