Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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;
            }
        }
        [...]
share|improve this question
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. –  Wescrock Dec 7 '12 at 17:30
    
Using HeidiSQL, a query takes almost zero time. phpMyAdmin is also fast. I'll post the connection code. –  Devils Child 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. –  Devils Child Dec 7 '12 at 17:42
add comment

1 Answer

up vote 4 down vote accepted

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|improve this answer
    
Changing $host to 127.0.0.1 really helped. Seems to be a DNS problem. Thank you! –  Devils Child Dec 7 '12 at 21:38
    
yup that connect using 127.0.0.1 was it.. Thanks!! –  dano Oct 4 '13 at 20:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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