I'd noticed for ages that a MySQL database connection over my LAN was significantly slower than a database connection over the Internet.
I'm running Windows 7 32bit and I'm connected to a switch using an Ethernet cable. The switch is connected to a modem/router which is where my Internet connection arrives in the building. I am not using WiFi.
I ran the following code:
//store current time $start = microtime(true); //connect to database outside my LAN $c1 = mysql_connect("126.96.36.199", "user1", "pass1"); mysql_select_db("database1", $c1); //print out the time taken in seconds echo microtime(true) - $start, "<br>"; //close the database connection mysql_close($c1); //store current time $start2 = microtime(true); //connect to database on my LAN $c2 = mysql_connect("192.168.0.10", "user2", "pass2"); mysql_select_db("database2", $c2); //print out time taken in seconds echo microtime(true) - $start2, "<br>"; //close database connection mysql_close($c2);
three times which returned the following times:
External WAN database: 0.054498910903931, 0.055356025695801, 0.05623197555542
Internal LAN database: 5.0052859783173, 5.0053160190582, 5.005627155304
The LAN file transfer speed (using Samba to share the drive on the Ubuntu machine) is approx 30MB/s and my broadband connection speed is 35Mbps down and 7Mbps up.
Anecdotally, logging into the local server using SSH is quite laggy.
I don't know what other information you might need, so please ask for more, I'm stumped as to why a local connection is so much slower!