What is the CGI

CGI stands for universal gateway interface. The Common Gateway Interface is an important Internet technology that allows a client to request data from a web browser to a program on a server. CGI describes a standard for transferring data between a server and a request handler. — Wikipedia

Simply put, CGI is a standard that defines how data should interact between a server (such as Nginx) and a processor (such as PHP). Without this standard, the server sends data to the handler in its own way, and the handler is supposed to recognize it. Therefore, a protocol is provided that all servers and processors agree on, specifying what data to pass and how to pass it.

So what is the data?

I think the data here should be divided into two parts. The first part is inbound: the server passes information to the handler, such as urls, request body, request headers, etc. The PHP parser (PHp-CGI) takes this information and processes it internally. The second part is output: the processor sends the response data back to the server. At this time, the data will be response and other response information. After the server gets the data, it will parse it through CGI and return it to the client after processing.

Is CGI that perfect?

Of course, the answer is no, every web request, implements the CGI process will fork a process for processing, after when the request processing, will be closed, so frequently to create destruction process, low efficiency, slow processing speed, and when the number of connections, too much process will consume more resources and memory.

What is the FastCGI

FastCGI is basically similar to CGI and is a language-neutral protocol. FastCGI was conceived to address the waste of resources caused by the frequent creation and destruction of CGI.

What is FPM

FPM, or phP-FPM, is officially called the Fastcgi Process Manager. Before we talk about FPM, we have to mention that PHP has officially launched phP-CGI.

Php-cgi is official, but when modifying the php.ini file, you need to restart php-cgi, and php-cgi does not support smooth restarts.

Php-fpm, an unofficial product added after PHP5.3, is a concrete implementation of the FastCGI protocol and is responsible for a pool of processes to manage requests from web servers.

CGI, FastCGI, phP-CGI, and php-FPM diagrams