Home  >  Article  >  Backend Development  >  Detailed explanation of the operating principle of Nginx+Php-fpm

Detailed explanation of the operating principle of Nginx+Php-fpm

移动用户-8334543
移动用户-8334543Original
2022-06-16 16:43:47178browse

1. User access process to dynamic PHP web pages

step1: The user sends the http request to the nginx server
step2: nginx will judge the request based on the URI and suffix visited by the user
step3: It can be seen from the second step that the user requests dynamic content. nginx will hand over the request to the fastcgi client and send the user's request to php-fpm through fastcgi_pass
If the user accesses static resources Well, that’s easy. nginx directly returns the static resources requested by the user to the user.
step4: After the wrapper receives the request transferred from php-fpm, the wrapper will generate a new thread to call the php dynamic program parsing server
step5: php will return the query results to nginx
step6: nginx constructs a response message and returns the result to the user

cgi protocol

cgi communication protocol

fastcgi protocol

fastcgi protocol is an extension of cgi The protocol efficiency is supplemented and improved, mainly optimizing the need to start a cgi interpreter process every time a request comes in. The cgi interpreter process no longer needs to reload the php.ini file and initialize the execution environment every time it receives a webserver request.

php-fpm process manager

php-fpm is an implementation of the fastcgi protocol and a process manager. It includes master and worker processes at startup. The master process is responsible for managing the worker process. There are generally multiple worker processes, which are used to listen on ports and receive requests from the webserver. Each worker process has a cgi process interpreter, which is used to execute PHP code.

What are the five-layer protocols of tcp?

Application layer, transport layer, network layer, data link layer, physical layer

Talk about tcp three-way handshake?

1. The client sends a connection request segment to the server, in which SYN is set to 1, and then selects a starting sequence number seq=x

2. The server receives After receiving the request message segment, send a confirmation message segment to the client, in which SYN and ACK are set to 1, the confirmation number field is x 1, and a starting sequence number seq=y

3 is generated. When After the client receives the confirmation message segment, it must send another confirmation message segment to the server, in which the ACK is set to 1, the confirmation number field is y 1, and the sequence number field is x 1

Note: SYN is Synchronization serial number, ACK is the confirmation serial number mark

nginx receives the request, finds the php file to be accessed according to the listening port, and establishes a connection with one of the resident memory fast-cgi programs through the socket, and transfers the received The data is passed to fast-cgi, and php-fpm manages the fast-cgi process. After it hangs, it starts up again. Fast-cgi executes the PHP program. After completing the data acquisition, it returns to nginx through the connection and returns to the user client.

What is the difference between cookie and session?

1. Cookies are stored on the browser, and sessions are stored on the server.

2. Others can analyze local cookies to perform cookie spoofing. Consider security when applying sessions

3. The storage limit of a single cookie is 4k, but the browser has no limit on sessions

The above is the detailed content of Detailed explanation of the operating principle of Nginx+Php-fpm. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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