XAMPP: Requests take far longer when connecting to a MySQL database

9,524

Check the Windows Hosts file here -

C:\Windows\system32\drivers\etc\hosts

Make sure that this line is in there...

127.0.0.1 localhost

And make sure that this line is commented out...

::1 localhost

Sometimes issues with IPv6 and/or localhost resolves can cause timeouts like this.

Also see if -

$host = '127.0.0.1'

makes any difference.

Share:
9,524

Related videos on Youtube

bytecode77
Author by

bytecode77

Updated on September 18, 2022

Comments

  • bytecode77
    bytecode77 over 1 year

    I'm developing in PHP and MySQL locally using XAMPP on Windows. The web site is fairly fast when not connecting to any database. However, when I connect to the MySQL database, a simple request now takes approximentaly a second.

    Note: This is not the case on my remote Debian vServer. My vServer handles requests fast, no matter if using a database or not.

    I use Windows 8 x64 and the latest version of XAMPP and I did not commit any changed to the configuration files.

    What could be the cause of this bad performance?^

    Edit: This is the connection code I use:

    $sql = new SqlConnection($cfgDbHost, $cfgDbUser, $cfgDbPassword);
    $sql->setCurrentDatabase($cfgDbDatabase);
    
    [...]
    
        class SqlConnection
        {
            private $Link, $CurrentDatabase, $IsConnected;
    
            function SqlConnection($host = 'localhost', $user = 'root', $pass = '')
            {
                $this->Link = @mysql_connect($host, $user, $pass);
                $this->IsConnected = $this->Link != NULL;
            }
            function setCurrentDatabase($database)
            {
                if (@mysql_select_db($database, $this->Link))
                {
                    $this->CurrentDatabase = $database;
                    return true;
                }
                else
                {
                    return false;
                }
            }
            [...]
    
    • Wes
      Wes over 11 years
      Use a SQL Browser (i.e.: HeidiSQL) and run some test queries directly against the database... do it on the server and from a remote computer and compare the times. It could be network, it could be memory, it could be MySQLs settings.
    • bytecode77
      bytecode77 over 11 years
      Using HeidiSQL, a query takes almost zero time. phpMyAdmin is also fast. I'll post the connection code.
    • bytecode77
      bytecode77 over 11 years
      I uploaded the relevant code. Also I'd like to note, that the connection alone is the part that takes all the time. Even when no queries are fired, it takes like a second longer.
  • bytecode77
    bytecode77 over 11 years
    Changing $host to 127.0.0.1 really helped. Seems to be a DNS problem. Thank you!
  • dano
    dano over 10 years
    yup that connect using 127.0.0.1 was it.. Thanks!!