源码

首页 » 归档 » 源码 » php – mysql_connect(localhost / 127.0.0.1)在Window…

php – mysql_connect(localhost / 127.0.0.1)在Window…


我使用的是Windows 7,Apache 2,PHP 5,MySQL 5,它们都在同一台机器上.
我发现了一个有趣的问题,我有以下代码:

    $sql = "select * from user1";
    $conn = mysql_connect("localhost", "root", "xxxxxxxx");
    mysql_select_db("test1");
    mysql_query("set names utf8");
    $result = mysql_query($sql, $conn);
    while ($row = mysql_fetch_assoc($result)){
        foreach ($row as $key => $value){
            echo $key." => ".$value." || ";
        }
        echo "
"; } mysql_free_result($result); mysql_close($conn);

上述代码的运行时间超过1秒.

当我使用127.0.0.1而不是localhost时,运行时间大约为10毫秒.

我试图在互联网上找到根本原因,结果如下:

I recently moved my development from XP to Windows 7 and found that webpages I had developed were taking 5 seconds long to load. This was unacceptable of course so I had to track down the problem.
I eventually tracked down the offending function/method pdo::construct. I also found that mysql_connect was taking about 1 second to make a connection. After a little googling I found an explaination that php had issues with IPv6 and that you could fix the problem by either disabling IPv6 or switching to the ipaddress 127.0.0.1 when making your connection.

我想知道PHP上的IPv6问题是什么,只是想深入了解.谢谢.

(0)

本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/php-mysql_connectlocalhost-127-0-0-1zaiwindow.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:9 月 26, 2019 at 01:16 上午

热评文章