CGI and FAST-CGI and PHP-FPM connection and difference

Simple and rude version:
cgi (public gateway interface)

||

According to the nginx configuration file, if you know that it is not a static file, you need to find a PHP parser To process

||

With URl, POST data, HTTP Header and query string
||

The corresponding CGI program, here is the PHP parser

||

The PHP parser will parse the php.ini file and initialize the execution environment

||

Process the request, return the processed result in the format specified by the CGI, and exit the process

||

The web server returns the result to the browser

>

Alright, CGI is a protocol
Fastcgi is used to improve the performance of CGI programs.

The PHP parser will parse the php.ini file and initialize the execution environment.
The standard CGI will execute these steps for every request. It’s too tiring, right and the processing time will be longer.< br>First, Fastcgi will first start a master, parse the configuration file, initialize the execution environment, and then start multiple workers. When the request comes, the master will pass it to a worker, and then immediately can accept the next request. In this way, repeated labor is avoided, and the efficiency is naturally high. And when the workers are not enough, the master can start several workers in advance according to the configuration and wait; of course, when there are too many idle workers, some will be stopped, which improves performance and saves resources. This is how fastcgi manages the process.

So what is PHP-FPM? It is a program that implements Fastcgi and was officially accepted by PHP.

As everyone knows, the interpreter of PHP is php-cgi. php-cgi is just a CGI program. It can only parse the request and return the result. It does not manage the process. So there are some programs that can schedule the php-cgi process.

Leave a Comment

Your email address will not be published.