How nginx and php communicate

(*-*)浩
Release: 2019-11-20 10:10:45
Original
5221 people have browsed it

How nginx and php communicate

Two communication methods between Nginx and PHP - unix socket and tcp socket

1. Both Nginx configurations (Recommended learning: nginx tutorial )

# unix socket

need to fill in the PID file running PID file running in the nginx configuration file address.

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;
}
Copy after login

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;
}
Copy after login

2. Comparison between the two

How nginx and php communicate

#As you can see from the above picture, unix socket reduces unnecessary tcp overhead. 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 connection-oriented protocols, 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 How nginx and php communicate. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template