Two communication methods between Nginx and PHP: unix socket and tcp socket
(Recommended tutorial: nginx tutorial)
1. Both Nginx configuration
unix socket
You need to fill in the pid file address of php-fpm running in the nginx configuration file.
location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; }
tcp socket
You need to fill in the ip address and port number of php-fpm running in the nginx configuration file.
location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; }
2. Comparison
Unix socket reduces unnecessary tcp overhead, while tcp needs to go through loopback and apply for temporary ports and tcp related resources. However, Unix socket is unstable when the concurrency is high. When the number of connections explodes, a large number of long-term caches will be generated. Without the support of a connection-oriented protocol, large data packets may directly go wrong without returning an exception.
Connection-oriented protocols such as tcp can more or less guarantee the correctness and integrity of communication.
The above is the detailed content of What are the two communication methods between nginx and php?. For more information, please follow other related articles on the PHP Chinese website!