Differences between mysql_connectlocalhost and 127.0.0.1 (network layer description) _ PHP Tutorial

Source: Internet
Author: User
Tags unix domain socket
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...

Related Article

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.