Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the relationship between FastCgi and PHP-fpm

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail the relationship between FastCgi and PHP-fpm. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

The relationship between FastCgi and PHP-fpm

I have looked up the relationship between fastcgi and php-fpm on the Internet. I have checked it for almost a week and basically read it all over. There are really different opinions and there is no authoritative definition.

Some people on the Internet say that fastcgi is an agreement, and php-fpm implements this protocol.

Some say that php-fpm is the manager of the fastcgi process, which is used to manage the fastcgi process

Some say that php-fpm is a patch for the php kernel.

Some say that after modifying the php.ini configuration file, there is no way to restart smoothly, so php-fpm is born.

Others say that PHP-CGI is the FastCGI manager that comes with PHP, so why get a php-fpm out of it?

First of all, what does CGI do?

The purpose of CGI is to ensure that the data transmitted by web server is in a standard format for the convenience of the writers of CGI programs.

Web server (such as nginx) is just a distributor of content. For example, if you request / index.html, web server will find the file in the file system and send it to the browser, where static data is distributed. Well, if the request is / index.php, and according to the configuration file, nginx knows that this is not a static file and needs to find a PHP parser to process it, then he will simply process the request and hand it over to the PHP parser. What data does Nginx pass to the PHP parser? There must be url, query string, POST data, and HTTP header. Well, CGI is a protocol that specifies which data to send and what format to pass to the rear to process the request.

When web server receives the request / index.php, it starts the corresponding CGI program, which is the parser of PHP. Next, the PHP parser parses the php.ini file, initializes the execution environment, processes the request, returns the processed result in the format specified by the CGI, and exits the process. Web server then returns the results to the browser.

Okay, CGI is a protocol, it has nothing to do with the process or anything.

And what is fastcgi?

Fastcgi is used to improve the performance of CGI programs.

Improve performance, so what is the performance problem with CGI programs?

"the PHP parser parses the php.ini file and initializes the execution environment." this is it. Standard CGI performs these steps for each request (don't get tired! Start the process very tired to say! So it takes a long time to process each time This is obviously unreasonable! So how does Fastcgi do it? First, Fastcgi starts a master, parses the configuration file, initializes the execution environment, and then starts multiple worker. When the request comes, the master is passed to a worker, and the next request can be accepted immediately. In this way, repetitive work is avoided, and the efficiency is naturally high. And when the worker is not enough, master can start several worker in advance according to the configuration; of course, when there are too many idle workers, some will be stopped, which improves performance and saves resources. This is fastcgi's management of the process.

And what is PHP-FPM?

Is a program that implements Fastcgi and has been officially accepted by PHP.

As we all know, the interpreter of PHP is php-cgi. Php-cgi is just a CGI program, he can only parse the request and return the result, not process management (your Majesty, my concubine really can't do it! So there are programs that can schedule php-cgi processes, such as spawn-fcgi, which is 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, a few years ago, people complained about the poor stability of PHP-FPM), and it is becoming more and more popular.

All right, let's finally come back to the above question.

Some people on the Internet say that fastcgi is an agreement, and php-fpm implements this protocol.

Yes.

Some say that php-fpm is the manager of the fastcgi process, which is used to manage the fastcgi process

Yes. The management object of php-fpm is php-cgi. However, php-fpm cannot be said to be the manager of the fastcgi process, because as mentioned earlier, fastcgi is a protocol, and it seems that no such process exists, and even if php-fpm does exist, it cannot manage it (at least for now).

Some say that php-fpm is a patch for the php kernel.

It used to be right. Because php-fpm was not included in the PHP kernel in the beginning, to use this feature, 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 integrated PHP-FPM, it was much more convenient to use the compilation parameter-- enalbe-fpm.

Some say that after modifying the php.ini configuration file, there is no way to restart smoothly, so php-fpm is born.

Yes, it is true that there is no way to restart the php-cgi process smoothly after modifying php.ini. Php-fpm 's mechanism for dealing with this is that the new worker uses a new configuration, and the existing worker can rest after dealing with the work at hand, through this mechanism to smooth the transition.

Others say that PHP-CGI is the FastCGI manager that comes with PHP, so why get a php-fpm out of it?

Wrong. Php-cgi is just a program that interprets PHP scripts.

This is the end of the article on "what is the relationship between FastCgi and PHP-fpm". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report