Find out the relationship between FastCgi and PHP-fpm, fastcgiphp-fpm_PHP tutorial-php Tutorial

Source: Internet
Author: User
[Go to] find out the relationship between FastCgi and PHP-fpm, fastcgiphp-fpm. [Switch] find out the relationship between FastCgi and PHP-fpm. fastcgiphp-fpm: some people on the Internet say that fastcgi is a protocol, and php-fpm implements this protocol; some say, the php-fpm is the fastcgi process [to] to find out the relationship between FastCgi and PHP-fpm, fastcgiphp-fpm

Problem: some say on the Internet that fastcgi is a protocol, and php-fpm implements this protocol; some say that php-fpm is the manager of the fastcgi process to manage fastcgi processes; some say, php-fpm is a patch of the php Kernel. some say that php has been modified. ini configuration file, there is no way to smooth restart, so the birth of the php-fpm; also said that the PHP-CGI is the FastCGI manager PHP built-in

First, what does CGI do? CGI is used to ensure that the data transmitted by the web server is in the standard format, so that the compilation of CGI programs is convenient.

Web server (such as nginx) is only the content distributor. For example, if the request/index.htmlThe web server will find the file in the file system and send it to the browser. static data is distributed here. Okay, if the request is/index.phpAccording to the configuration file, nginx knows that this is not a static file and needs to be handled by the PHP parser. then nginx will simply process this request and hand it over to the PHP parser. What data will Nginx transmit to the PHP parser? There must be a url, a query string, or a POST data, and a few HTTP headers. okay, CGI is the protocol that specifies the data to be transmitted and the format in which the request is sent to the backend. Think about where the users you use in PHP code come from.

When the web server receives/index.phpAfter this request, the corresponding CGI program will be started. here is the PHP parser. 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 CGI, and exits the process. The web server then returns the result to the browser.

Okay, CGI is a protocol. it has nothing to do with the process. What is fastcgi? Fastcgi is used to improve CGI program performance.

To improve the performance, what is the problem with the CGI program performance? "The PHP parser parses the php. ini file and initializes the execution environment. The standard CGI performs these steps for each request! I am tired of starting the process !), Therefore, the processing time is 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 over, the master will pass it to a worker, and then immediately receives the next request. In this way, repetitive work is avoided, and the efficiency is naturally high. In addition, when the worker is not enough, the master can start several workers in advance according to the configuration. of course, when there are too many idle workers, some will also be stopped, which improves performance and saves resources. This is how fastcgi manages processes.

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

As we all know, the interpreter for PHP is php-cgi. Php-cgi is just a CGI program. it can only parse requests, return results, and no process management. (Huang Shang, Chen really cannot do it !) So there are some programs that can schedule the php-cgi process, such as spawn-fcgi separated by lighthttpd. Good PHP-FPM is such a Dongdong, after a long period of development, gradually get everyone's approval (you know, a few years ago, but complained that PHP-FPM stability is too bad), is becoming more and more popular.

Okay. come back to your question.
1. some say on the Internet that fastcgi is a protocol, which is implemented by php-fpm.

Yes.

2. 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. But it cannot be said that php-fpm is the manager of the fastcgi process, because fastcgi is a protocol, and it seems that no such process exists, even if php-fpm exists, it cannot be managed (at least currently ). Some say that php-fpm is a patch of the php kernel before. Because php-fpm was not included in the PHP kernel at the beginning, to use this function, you need to find the same php-fpm version as the source code to patch the kernel and then compile it. Later PHP kernel integrated with the PHP-FPM will be more convenient to use--enalbe-fpmCompile the parameter.

3. some people say that after the php. ini configuration file is modified, it cannot be restarted smoothly, so php-fpm is born.

Yes. after modifying php. ini, the php-cgi process cannot be restarted smoothly. The processing mechanism of php-fpm is that the new worker uses a new configuration, and the existing worker can stop working after it completes processing. this mechanism is used to smooth the process.

4, there is also said that the PHP-CGI is PHP built-in FastCGI manager, so why do you get a php-fpm out

No. Php-cgi is just a program that explains PHP scripts.

From https://segmentfault.com/q/1010000000256516

Problem: some say on the Internet that fastcgi is a protocol, and php-fpm implements this protocol; some say that php-fpm is a fastcgi process...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.