我的本地系统需要大约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