博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP curl超时问题
阅读量:4936 次
发布时间:2019-06-11

本文共 1764 字,大约阅读时间需要 5 分钟。

    今天调试一个非常老的代码时  发现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 意思相同 只是超时单位为毫秒了。。。

 

转载于:https://www.cnblogs.com/glory-jzx/p/4581413.html

你可能感兴趣的文章
CSS实例:图片导航块
查看>>
python进阶七_文件操作(三)
查看>>
window的对象有哪些(笔记)
查看>>
成绩查询方法指引Pmp
查看>>
Boolean Expressions
查看>>
They Are Everywhere
查看>>
数据结构--汉诺塔递归Java实现
查看>>
day14 多态与抽象
查看>>
Eclipse CDT 出现 launch failed Binary not found
查看>>
apache jmeter
查看>>
Linux 基本命令
查看>>
RedHat7.0 网络源的配置
查看>>
(Mark)JS中关于闭包
查看>>
流程结构图
查看>>
ios端web app在键盘升起后缩小view防止界面仍可上下滑动
查看>>
从service弹出系统级自定义提示框,可在任意页面弹出
查看>>
Bootstrap简单介绍
查看>>
字典序最小问题
查看>>
iOS Touch ID 身份认证
查看>>
springboot 注解笔记
查看>>