PHP curl超时问题
2015-06-16 17:39
555 查看
今天调试一个非常老的代码时 发现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
建立连接时候的超时设置
[b]CURLOPT_TIMEOUT [/b]
接收信息时的超时设置
[b]CURLOPT_CONNECTTIMEOUT_MS, [b] [b]CURLOPT_TIMEOUT_MS 意思相同 只是超时单位为毫秒了。。。[/b][/b][/b]
发现是后台脚本一直等待 排查到最后发现是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
建立连接时候的超时设置
[b]CURLOPT_TIMEOUT [/b]
接收信息时的超时设置
[b]CURLOPT_CONNECTTIMEOUT_MS, [b] [b]CURLOPT_TIMEOUT_MS 意思相同 只是超时单位为毫秒了。。。[/b][/b][/b]
相关文章推荐
- PHP处理postfix邮件内容的方法
- PHP限制HTML内容中图片必须是本站的方法
- php7 run
- PHP正则获取字符串中数字
- Yii2:推荐一个方法arrayHelper::map()
- win7下开启FTP服务
- Yii2:推荐一个方法arrayHelper::map()
- php面向对象基础概念(重载新的方法parent::)
- PHP-SMTP发送邮件
- phpcms v9最常用的22个调用代码
- TP的多表查询+分页范例
- PHP效率优化
- 从新安装Zend studio,从新安装svn导致不能share项目的问题
- DEDE常用标签
- phpcms_v9 多图字段 内容页,首页,分页自定义字段调用
- redhat 下基本命令和php、ftp服务
- PHPExcel导出数据
- phpcms v9中调用栏目及调用多个子栏目中的文章列表
- 如何判断一个请求为ajax请求?
- PHP json_encode() 函数介绍