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);


    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;
                return false;
  • 1
    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. – Wes Dec 7 '12 at 17:30
  • Using HeidiSQL, a query takes almost zero time. phpMyAdmin is also fast. I'll post the connection code. – bytecode77 Dec 7 '12 at 17:37
  • 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 Dec 7 '12 at 17:42

Check the Windows Hosts file here -


Make sure that this line is in there... 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 = ''

makes any difference.

  • Changing $host to really helped. Seems to be a DNS problem. Thank you! – bytecode77 Dec 7 '12 at 21:38
  • yup that connect using was it.. Thanks!! – dano Oct 4 '13 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.