加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 为什么我的MySQLi连接这么慢?

发布时间:2020-12-13 14:06:32 所属栏目:PHP教程 来源:网络整理
导读:我的本地系统需要大约1秒建立一个 MySQLi连接.码: $db = new mysqli( 'localhost','root','pass','mydb' ); 为什么这么慢?这是正常吗?可以改善吗? 将“localhost”切换到127.0.0.1. 所以,而不是: $db = new mysqli( 'localhost','mydb'); 使用: $db =
我的本地系统需要大约1秒建立一个 MySQLi连接.码:
$db = new mysqli( 'localhost','root','pass','mydb' );

为什么这么慢?这是正常吗?可以改善吗?

将“localhost”切换到127.0.0.1.

所以,而不是:

$db = new mysqli( 'localhost','mydb');

使用:

$db = new mysqli( '127.0.0.1','mydb');

看到这个问题似乎很受欢迎,很多人都想知道WHY this is happening:

This is caused because the MySQL client will do an IPV6
lookup for the hostname. If this fails (and in this case,it obviously
does),it will then attempt to do an IPV4 lookup. Between the IPV6
(AAAA) lookup failing and the IPV4 (A) lookup succeeding,what we get
is a connection timeout cycle that lasts about 1-2 seconds.

值得注意的是,这个问题似乎只在Windows 7和之后发生.在Windows 7之前,本地主机解析由主机文件处理,该文件预先配置了127.0.0.1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读