Differences between mysql_connectlocalhost and 127.0.0.1 (network layer description ). Differences between mysql_connectlocalhost and 127.0.0.1 (network layer description) This article mainly introduces the differences between mysql_connectlocalhost and 127.0.0.1 (network layer description). This article describes the differences between mysql_connect localhost and 127.0.0.1 (network layer description)
This article mainly introduces the differences between mysql_connect localhost and 127.0.0.1 (network layer). This article explains their differences from the network communication layer. For more information, see
Connects. php
The code is as follows:
Mysql_connect ('2017. 0.0.1 ', 'root', 'zzzizzz1 ');
Mysql_connect ('localhost', 'root', 'zzzizzz1 ');
Use strace to obtain system calls:
The code is as follows:
Strace php connects. php 2> & 1 | grep connect
#127.0.0.1-> internet socket
Connect (3, {sa_family = AF_INET, sin_port = htons (3306), sin_addr = inet_addr ("127.0.0.1")}, 16) =-1 EINPROGRESS (Operation now in progress)
# Localhost-> unix domain socket
Connect (7, {sa_family = AF_FILE, path = "/var/run/mysqld. sock"}, 110) = 0
Socket was originally designed for network communication, but later an IPC mechanism was developed on the Socket framework, namely, UNIX Domain Socket.
Although the network socket can also be used for inter-process communication between the same host (through the loopback address 127.0.0.1), the UNIX Domain Socket is more efficient for IPC:
Without going through the network protocol stack, packaging, unpacking, calculating the checksum, maintaining the serial number and response, and copying application layer data from one process to another.
This is because the IPC mechanism is essentially reliable communication, and the network protocol is designed for unreliable communication.
UNIX Domain Socket also provides two API interfaces: stream-oriented and packet-oriented, which are similar to TCP and UDP. However, the UNIX Domain Socket for message (UDP) is also reliable, messages are neither lost nor disordered.
Http://www.bkjia.com/PHPjc/974523.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/974523.htmlTechArticlemysql_connect localhost and 127.0.0.1 difference (network layer) This article mainly introduces the difference between mysql_connect localhost and 127.0.0.1 (network layer), this article from the network communication layer...