title: mysql_connect (localhost / 127.0.0.1) slow on Windows platform
body: <p>I am using Windows 7, Apache 2, PHP 5, MySQL 5, all are on the same machine.
  I have found an interesting issue, I have the following code:</p>
  
  <pre><code>    $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 =&gt; $value){
              echo $key." =&gt; ".$value." || ";
          }
          echo "&lt;br/&gt;";
      }
      mysql_free_result($result);
      mysql_close($conn);
  </code></pre>
  
  <p>The running time for the above code is over 1 second.</p>
  
  <p>When I use <code>127.0.0.1</code> instead of <code>localhost</code>, the running time is around 10 ms.</p>
  
  <p>I tried to find the underlying reason on the internet, and this is the result:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>I wonder what the issue of IPv6 on PHP is, just want to get a deeper understaning. Thanks.</p>