What is the relationship between php-fpm and fastcgi in nginx

We know that in nginx.conf, you need to configure fastCGI,php. You need to install the php-fpm extension and start the php-fpm daemon before nginx can parse the php script.

Let"s get to the point:
1. In Nginx, is it necessary to configure php-fpm to parse PHP?
2. Is it php-fpm or fastcgi or something else that parses PHP?
3. What is the phpcgi relationship between Fastcgi and Fastcgi?
4. Some people say that fastcgi is an interface protocol that decouples nginx and php. Php-fpm is a tool for implementing this interface. I don"t know if this understanding is correct.

after reading a lot of related articles, I feel that I don"t know what I"m talking about, and no one has explained it clearly. I hope you can talk about these questions with your own understanding.

Mar.11,2021

  1. can't parse php files even if php-fpm is configured. Nginx is just a forward, and fastcgi_pass is like proxy_pass, forwarding
  2. it is php-fpm who parses PHP
  3. php-cgi implements CGI (Universal Gateway Interface, which requires a new fork process to process new requests, which is inefficient), and php-fpm implements fastcgi (the process survives all the time)
  4. fastcgi is a protocol. According to the protocol, php-fpm processes requests and responses. According to this protocol, nginx sends requests to php-fpm and collects data returned by php-fpm

well, let's talk about my understanding:

  1. Nginx itself cannot parse php, so it needs an execution environment, (runtime), to parse it, which is the runtime environment where zend,php-fpm is responsible for accepting requests from nginx and passing them to zend.
  2. fastcgi does not care about parsing, it is responsible for how to send client requests to php-fpm, which is a standard, and Nginx implements it.
  3. cgi is a standard for data exchange, and fastcgi is its plus version. Php-cgi (note the connector in the middle) is supposed to be the predecessor of php-fpm, but it is a cgi program itself, unlike php-fpm at the manager level, so it has been gradually replaced (at first php-fpm was just a plug-in, then included by the core).
  4. is basically what I said above.

(if there is any problem, please point it out, thank you)

< hr >

in addition, it is recommended to take a look at the answer under ~

. < hr >

it's nice to see two flowcharts, about CGI and FastCGI, turn around:

  • CGI
    191104434855332.png
  • FastCGI
    191104485636450.png

Source of the picture: Nginx + CGI/FastCGI + C/Cpp


user request-> nginx (webserver)-> fastcgi (nginx cannot communicate directly with php, only through fastcgi interface)-> php-fpm (PHPFastCGI Manager)-> php-cgi- > php


thanks
cgi is a protocol, fastcgi is a high-level protocol, which is the same as our commonly used http and https protocols.
php-cgi is responsible for parsing cgi and fastcgi programs.
php-fpm is just a process manager that manages processes. He manages programs that can parse cgi and fastcgi, which is more commonly called sapi (server-side application programming port)
now let's talk about your problem

1. nginxPHP,fastcgi,php-fpm,fpmphp-cginginx.fpm,.apachecgi.
2. php-fpmfastcgi,php-cgi
3. php-fpmfastcgiphp-cgi.
4. .php-fpm.,php-cgi.
For those who don't understand, take a look at php7-internal . It's pretty good.
only point 4, Weisa will say so. This is based on the source code of php-fpm. Php-fpm does not parse and process requests. The specific request processing is in worker, let's call it php-cgi. The specific fpm implementation looks something like this.

  

the relationship between php-fpm and fastcgi is similar to that between
browser and http

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9ca72-18ef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9ca72-18ef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?