First of all, what does CGI do? CGI is to ensure that the data passed by the web server is in a standard format, which is convenient for the writers of CGI programs.
Web server (such as nginx) is just the distributor of content. For example, if /index.html is requested, the web server will find this file in the file system and send it to the browser, where static data is distributed. Well, if the request is /index.php, according to the configuration file, nginx knows that this is not a static file and needs to find a PHP parser to handle it, then he will simply process the request and hand it over to the PHP parser. What data will Nginx send to the PHP parser? You must have the url, the query string, and the POST data. The HTTP header must not be less. Okay, CGI specifies what data to be transmitted and in what format to pass to the protocol for processing this request. Think about it carefully, where do the users you use in the PHP code come from.
When the web server receives the /index.php request, it will start the corresponding CGI program, here is the PHP parser. Next, the PHP parser will parse the php.ini file, initialize the execution environment, then process the request, and then return the processed result in the format specified by the CGI, and exit the process. The web server then returns the result to the browser.
Well, CGI is a protocol, it has nothing to do with the process. So what is fastcgi? Fastcgi is used to improve the performance of CGI programs.
Improve performance, so what is the performance problem of CGI program? “The PHP parser will parse the php.ini file and initialize the execution environment”, that’s it. Standard CGI will perform these steps for each request (not idle! Startup process is very tiring!), so the processing time for each time will be relatively long. This is obviously unreasonable! So how does Fastcgi do it? First, Fastcgi will 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 (the emperor, the concubine really can’t do it!), so there are some programs that can schedule the php-cgi process. For example, spawn-fcgi separated by lighthttpd. Well, PHP-FPM is also such a thing. After a long period of development, it has gradually been recognized by everyone (you know, in the past few years, everyone complained about the poor stability of PHP-FPM), and it has become more and more popular.
Okay, finally come back to your question. Some people on the Internet say that fastcgi is a protocol, and php-fpm implements this protocol
Yes.
Some people say that php-fpm is a fastcgi process manager, which is used to manage fastcgi processes.
Yes. The management object of php-fpm is php-cgi. But it cannot be said that php-fpm is the manager of the fastcgi process, because fastcgi is a protocol mentioned earlier, it seems that there is no such process, even if there is php-fpm, it cannot be managed (at least for now). Some say that php-fpm is a patch of the php kernel
It was right before. Because php-fpm was not included in the PHP kernel at the beginning, to use this function, you need to find the same version of php-fpm as the source code to patch the kernel, and then compile it. Later, after the PHP kernel integrates PHP-FPM, it is much more convenient, just use the compilation parameter –enalbe-fpm.
Some people say that after modifying the php.ini configuration file, there is no way to restart smoothly, so php-fpm was born
Yes, after modifying php.ini, the php-cgi process is indeed There is no way to restart smoothly. The processing mechanism of php-fpm is that a new worker uses a new configuration, and the existing worker can rest after processing the work at hand, and smooth transition through this mechanism.
Some people say that PHP-CGI is the FastCGI manager that comes with PHP, so why do you get php-fpm out again?
No. php-cgi is just a program that explains PHP scripts.
First of all, what does CGI do? CGI is to ensure that the data passed by the web server is in a standard format, which is convenient for the writers of CGI programs.
Web server (such as nginx) is just the distributor of content. For example, if /index.html is requested, the web server will find this file in the file system and send it to the browser, where static data is distributed. Well, if the request is /index.php, according to the configuration file, nginx knows that this is not a static file and needs to find a PHP parser to handle it, then he will simply process the request and hand it over to the PHP parser. What data will Nginx send to the PHP parser? You must have the url, the query string, and the POST data. The HTTP header must not be less. Okay, CGI specifies what data to be transmitted and in what format to pass to the protocol for processing this request. Think about it carefully, where do the users you use in the PHP code come from.
When the web server receives the /index.php request, it will start the corresponding CGI program, here is the PHP parser. Next, the PHP parser will parse the php.ini file, initialize the execution environment, then process the request, and then return the processed result in the format specified by the CGI, and exit the process. The web server then returns the result to the browser.
Well, CGI is a protocol, it has nothing to do with the process. So what is fastcgi? Fastcgi is used to improve the performance of CGI programs.
Improve performance, so what is the performance problem of CGI program? “The PHP parser will parse the php.ini file and initialize the execution environment”, that’s it. Standard CGI will perform these steps for each request (not idle! Startup process is very tiring!), so the processing time for each time will be relatively long. This is obviously unreasonable! So how does Fastcgi do it? 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 (the emperor, the concubine really can’t do it!), so there are some programs that can schedule the php-cgi process. For example, spawn-fcgi separated by lighthttpd. Well, PHP-FPM is also such a thing. After a long period of development, it has gradually been recognized by everyone (you know, in the past few years, everyone complained about the poor stability of PHP-FPM), and it has become more and more popular.
Okay, finally come back to your question. Some people on the Internet say that fastcgi is a protocol, and php-fpm implements this protocol
Yes.
Some people say that php-fpm is a fastcgi process manager, which is used to manage fastcgi processes.
Yes. The management object of php-fpm is php-cgi. But it cannot be said that php-fpm is the manager of the fastcgi process, because fastcgi is a protocol mentioned earlier, it seems that there is no such process, even if there is php-fpm, it cannot be managed (at least for now). Some say that php-fpm is a patch for the php kernel
It was right before. Because php-fpm was not included in the PHP kernel at the beginning, to use this function, you need to find the same version of php-fpm as the source code to patch the kernel, and then compile it. Later, after the PHP kernel integrates PHP-FPM, it is much more convenient, just use the compilation parameter –enalbe-fpm.
Some people say that after modifying the php.ini configuration file, there is no way to restart smoothly, so php-fpm was born
Yes, after modifying php.ini, the php-cgi process is indeed There is no way to restart smoothly. The processing mechanism of php-fpm is that a new worker uses a new configuration, and the existing worker can rest after processing the work at hand, and smooth transition through this mechanism.
Some people say that PHP-CGI is the FastCGI manager that comes with PHP, so why do you get php-fpm out again?
No. php-cgi is just a program that explains PHP scripts.