Home  >  Article  >  Backend Development  >  The relationship between nginx and php-fpm

The relationship between nginx and php-fpm

(*-*)浩
(*-*)浩Original
2019-09-03 13:19:314132browse

The relationship between nginx and php-fpm

php-fpm is the fastCGI process manager(Recommended learning: web front-end video tutorial)

1. Web Load the FastCGI process manager (IIS ISAPI or Apache Module) when the Server starts Server connection.

3. When the client request reaches the Web Server, the FastCGI process manager selects and connects to a CGI interpreter. The web server sends CGI environment variables and standard input to the FastCGI subprocess php-cgi.

4. After the FastCGI sub-process completes processing, it returns standard output and error information to the Web Server from the same connection. When the FastCGI child process closes the connection, the request is processed. The FastCGI child process then waits for and handles the next connection from the FastCGI process manager (running in the Web Server). In CGI mode, php-cgi exits at this point.

In the above case, you can imagine how slow CGI usually is. Every web request to PHP must reparse php.ini, reload all extensions and reinitialize all data structures. With FastCGI, all of this happens only once, when the process starts. An added bonus is that persistent database connections work.

FastCGI is a protocol that serves as a bridge between applications and WEB servers. Nginx cannot communicate directly with PHP-FPM, but passes the request to PHP-FPM for processing through FastCGI.

location ~ \.php$ {
    try_files $uri /index.php =404;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}
Here fastcgi_pass forwards all php requests to php-fpm for processing. You can see through the netstat command that the process running on port 127.0.0.1:9000 is php-fpm.

The above is the detailed content of The relationship between nginx and 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
Previous article:What can phpmyadmin do?Next article:What can phpmyadmin do?