Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize Communication between nginx and php-fpm

Shulou Source: shulou.com Published: 2022-06-02 05:58:25 09月12日 Update

Today, I will talk to you about how to achieve communication between nginx and php-fpm. Many people may not know much about it. In order to make you understand better, the editor summed up the following content for you. I hope you can get something according to this article.

Unix socket is faster than tcp and consumes less resources because socket communicates between nginx and php-fpm processes, while tcp needs to go through a local loopback driver and apply for temporary ports and tcp related resources.

Unix socket will appear to be less stable, and when the number of concurrent connections breaks out, a large number of long-term caches will be generated. In the absence of connection-oriented protocol support, large packets are likely to go wrong directly and will not return an exception. The connection-oriented protocol such as TCP can guarantee the correctness and integrity of communication.

Tcp mode: tcp protocol listens to native port 9000, which needs to be connected through the network, occupying ports and network resources.

Socket mode: use unix domain socket to connect sockets / dev/shm/php-cgi.sock, do not go to the network, faster

The nginx server module sets the fastcgi:

Tcp mode:

Fastcgi_pass 127.0.0.1:9000

Socket mode:

Fastcgi_pass unix:/dev/shm/php-cgi.sock

Configure link snooping in php-fpm.conf:

Tcp mode:

Listen = 127.0.0.1 9000

Socket mode:

Listen = / dev/shm/php-cgi.sock

/ dev/shm is the memory file system mount point, which is faster than the default / tmp/php-cgi.sock disk file

After reading the above, do you have any further understanding of how to communicate between nginx and php-fpm? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Mode communication content port network resource between file faster monitor memory loopback socket integrity situation data more module correctness knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Tech Info Shulou Technology vpn Docker