mysql_connect the difference between localhost and 127.0.0.1 (Network layer Elaboration)
This article mainly introduces the difference between mysql_connect localhost and 127.0.0.1 (Network layer Elaboration), this article from the network communication level explained their differences, the need for friends can refer to the following
connects.php
The code is as follows:
mysql_connect (' 127.0.0.1 ', ' root ', ' zzzizzz1 ');
mysql_connect (' localhost ', ' root ', ' zzzizzz1 ');
To get the system call using Strace:
The code is as follows:
Strace php connects.php 2>&1 | grep Connect
#127.0.0.1 Internet sockets
Connect (3, {sa_family=af_inet, sin_port=htons (3306), sin_addr=inet_addr ("127.0.0.1")}, +) =-1 einprogress (Operation Now in progress)
UNIX domain sockets #localhost
Connect (7, {sa_family=af_file, path= "/var/run/mysqld/mysqld.sock"}, 110) = 0
Socket was originally designed for network communication, but later in the framework of the socket developed an IPC mechanism, UNIX Domain Socket.
Although the network socket can also be used for interprocess communication with the same host (via loopback address 127.0.0.1), Unix Domain sockets are more efficient for IPC:
There is no need to go through the network protocol stack, do not need to package unpacking, calculate checksums, maintain serial numbers and responses, etc., just copy the application layer data from one process to another process.
This is because the IPC mechanism is inherently reliable communication, and network protocols are designed for unreliable communications.
UNIX domain sockets also provide both stream-oriented and packet-oriented API interfaces, similar to TCP and UDP, but message-oriented (UDP) UNIX domain sockets are also reliable, and messages are neither lost nor sequenced.
http://www.bkjia.com/PHPjc/974523.html www.bkjia.com true http://www.bkjia.com/PHPjc/974523.html techarticle mysql_connect localhost and 127.0.0.1 differences (network layer Elaboration) This article mainly introduces the difference between mysql_connect localhost and 127.0.0.1 (Network layer Elaboration), this paper from the network communication layer ...