mysql_connect the difference between localhost and 127.0.0.1 (Network layer Elaboration) _php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.