CGI fastcgi php-cgi PHP-FPM

Source: Internet
Author: User

In the current standard environment lamp and LNMP PHP always add an extension, that is php-fpm, but this thing, exactly what is going on, today to say that my understanding

First, the CGI and fast CGI

Cgi:

All know that PHP is an interpreted language, then need to have something to explain it, CGI is such a thing, it is a protocol, not what services.

principle:

                  When Web server receives /index.php This request will start the corresponding CGI program, which is the parser for PHP. The PHP parser then parses the php.ini file, initializes the execution environment, then processes the request, and then returns the processed result in a format specified by the CGI, exiting the process. Web server then returns the result to

Performance bottlenecks:

Each request will allow CGI to repeat the above steps for each request, that is, to start the process so that the CGI will work very slowly under high concurrency and high traffic.

FastCGI

It is also an interpreter, in fact, it is not much different from the CGI in nature, the key point is that the processing speed of the request a lot faster, literally can see out

Principle:

First fastcgi starts a master master process, initializes the environment, and then starts multiple worker processes, when there is a when the request comes in, master passes a handler for the worker, and then immediately processes the next, when When the worker is not available, Master will pre-boot several as backup, and when the worker is too many, master will stop several, this can not only make the environment initialization for reuse, but also save the system resources, improve the request processing speed

php-cgi

is actually the CGI protocol.

php-fpm

The same is true of the FASTCGI protocol, but the PHP-FPM management is actually php-fastcgi


Following is a question and answer about PHP-CGI and php-fpm (from online)

Some say that PHP-FPM is the manager of the fastcgi process, used to manage the fastcgi process

Right. 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 the fastcgi is a protocol, it seems that no such process exists, even if there is php-fpm can not manage him (at least for now). Some say that php-fpm is a patch for the PHP kernel

used to be right. Because PHP-FPM is not included in the PHP kernel at the beginning, to use this function, we need to find the same version of the source code php-fpm the kernel patch, and then compile. Later, after the PHP kernel integrates php-fpm, it is much easier to use --enalbe-fpm this compilation parameter.

Some said that after modifying the php.ini configuration file, there is no way to smooth the restart, so the birth of PHP-FPM

Yes, after modifying php.ini, the php-cgi process does not have the means to smooth the restart. PHP-FPM This mechanism is the new worker with a new configuration, the already existing workers can rest after processing the hands of the work, through this mechanism to smooth over.

Also say php-cgi is PHP comes with the fastcgi manager, then why do you get a php-fpm out

Wrong. PHP-CGI is just a program that explains PHP scripts.




CGI fastcgi php-cgi PHP-FPM

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.