Turn: Use UNIX sockets to accelerate PHP-FPM, MySQL, and Redis connections

Source: Internet
Author: User
Tags fpm

The server for the worm is running on a standalone basis. It is estimated that php-fpm and redis can coexist on a single machine for a long time, in addition to MySQL. (say that the server has already reached a single day 20 million + dynamic request, so I am very optimistic about the large flow of the single-machine to get the worm)

If it is a stand-alone service, actually do not need to use IP even 127.0.0.1 such IP to connect mysql/redis/php, because even 127.0.0.1 is to go to the TCP/IP layer.

UNIX provides a UNIX socket for single-machine port access, and many articles refer to using a UNIX socket to increase connection speed.

I tested it briefly, 200 Redis requests take 38ms, if changed to UNIX socket, immediately dropped to 27ms. This is almost instantaneous, 10ms gap is enough to let us have the power to change the IP to UNIX socket mode.

Mysql (PDO) method for enabling UNIX sockets

1. In the PDO DSN: Original write host:xxx, change to Unix_socket:/var/run/mysqld/mysqld.sock (of course you can be in my.cnf inside set into another)

2. Give MySQL user name @localhost, set access rights. Because Unix_socket is not the host, so using the UNIX socket connection Mysql,mysql will be forced to think that the user is from localhost, so be sure to [email protected] Set permissions, not [email Protected] '% '

Redis (Phpredis) method for enabling UNIX sockets

1.redis does not open the UNIX socket by default and needs to be modified in/etc/redis/redis.conf. Note Unixsocketperm 777

Unixsocket/var/run/redis/redis.sockunixsocketperm 777

2. Connect with Phpredis:

$redis->connect ('/var/run/redis/redis.sock ')

Nginx + php-fpm How to enable UNIX sockets

1.PHP-FPM in the pool configuration file:

Listen =/var/run/php5-fpm.sock;

In the 2.nginx sites configuration file:

Fastcgi_pass   Unix:/var/run/php5-fpm.sock;

Because of the number of Redis connections, Redis uses UNIX sockets the most obvious, MySQL second, PHP basically no use of sock are almost

Turn: Use UNIX sockets to accelerate PHP-FPM, MySQL, and Redis connections

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.