- Does using
localhostinmysql_connect()make the connection faster than using127.0.0.1? - What is the connection type between the PHP script and mySQL (when using the
mysql_connect()function) ? Is it TCP/IP?
|
|
|
|||||||||||||||||||||
|
|
"localhost" means local socket connection while 127.0.0.1 is TCP/IP. And yes, sockets are faster than TCP/IP. Cite from http://pl.php.net/mysql_connect
|
|||||||||||||
|
|
Nope, the 127.0.0.1 is recommended to use , because Windows 7 has a problem with choosing between IPv6 & IPv4. I tried this and if I used localhost, the page has reloading about 1sec (1,04sec) and when i used 127.0.0.1, the page has reloading 50ms. Both were used under Windows 7. |
|||||
|
|
Php site says: Note:
I guess the speed difference would be too low that it's something you should'nt be worried about. |
|||
|
|
|
For Unix, add to the client block after
|
||||
|
|
|
For macs, here's the solution: Connect to MySQL using localhost instead of 127.0.0.1 on a MAC. For a long while now I’ve been connecting to MySQL on my development platform with 127.0.0.1 because for some reason localhost didn’t work. Turns out it’s because 127.0.0.1 uses TCP/IP and localhost uses sockets. The php.ini file points to the wrong place for the mysql.sock so all you have to do is change it, restart apache and voila!
Note: If you don’t have a php.ini file, you need to copy the provided default called php.ini.default
via http://madproject.com/general/connect-to-mysql-using-localhost-instead-of-127-0-0-1-on-a-mac/ |
|||
|
|