• (转)php-curl响应慢(开发微信授权登陆时碰到的问题)


    最近在做一个php小项目的时候,发现curl调用微信的授权api.weixin.qq.com,经常是需要等待很久,但是有时候却很快。

    刚开始以为是网络慢问题,没去注意。后面通过打上时间日志观察发现,慢的时候基本是在5秒。既然那么有规律了,那肯定是有某个问题的。

    http请求的初始过程是什么呢?dns解析。

    通过ping和wget命令,发现确实在域名解析的那个过程很慢。所以,最终在host直接写死域名,解决了这个问题。

    (

    我也是,呵呵,省事,后期可以考虑安装dns缓存服务

    vim /etc/hosts 增加2行(微信支付好像用到的就是这个2个域名,前面的ip,请以你服务器上ping出来的为准)

    140.207.135.108 api.weixin.qq.com
    140.207.69.101 api.mch.weixin.qq.com

    )

    为什么是5秒(的确是5s,郁闷)呢?

    我们知道配置dns服务的地址在/etc/resolv.conf。

    通过man resolv.conf可以找到

    timeout:n
                               sets the amount of time the resolver will wait for
                               a response from a remote name server before retry-
                               ing the query via a different name server.  Mea-
                               sured in seconds, the default is RES_TIMEOUT (see
                               <resolv.h> ).

    查看/usr/include/resolv.h 可以找到这行代码 # define RES_TIMEOUT                5        /* min. seconds between retries */

    问题是解决了,但是却引申出了很多知识点。

    dns的解析默认超时时间是5秒

    网上说,有可能是开启了ipv6却没有给这个域名分配ipv6的地址,通过查看vim /etc/modprobe.conf,发现没有开启ipv6功能。

    查看域名的解析过程有dig命令

  • 相关阅读:
    【pycharm 密钥】pycharm 2017 密钥
    【jenkins 忘记密码】忘记Jenkins管理员密码的解决办法
    【git 报错】Could not read from remote repository.Please make sure you have the correct access rights.
    【pycharm 警告】unittest RuntimeWarning: Parent module ” not found while handling absolute import
    【python接口自动化测试教程】00---00章节就代表开篇吧
    【python-strip】Python strip()方法
    认识map-reduce
    subprocess实用手册
    k8s学习路线
    nginx小知识
  • 原文地址:https://www.cnblogs.com/showker/p/5747309.html
Copyright © 2020-2023  润新知