CGI FASTCGI PHP-FPM

Source: Internet
Author: User
Tags php source code

The CGI (Common Gateway Interface) CGI full name is a "public Gateway Interface" (Common Gateway Interface), a tool for the HTTP server to "talk" to programs on your or other machines, and its programs must be run on a network server. CGI can be written in any language, as long as the language has standard input, output, and environment variables. such as PHP,PERL,TCL and so on. Fastcgifastcgi is like a resident (long-live) CGI, which can be executed all the time, so long as it is activated, it will not take a moment to fork once (this is the most notorious fork-and-execute mode of CGI).
It also supports distributed operations where the FastCGI program can execute and accept requests from other Web servers on hosts other than the Web server. FastCGI is a language-independent, extensible architecture for CGI open extensions whose main behavior is to keep the CGI interpreter process in memory and thus achieve high performance.
As we all know, the repeated loading of CGI interpreter is the main reason of poor CGI performance, if the CGI interpreter remains in memory and accepts the FASTCGI process manager scheduling, it can provide good performance, scalability, fail-over characteristics and so on. PHP-FPMPHP-FPM is a PHP fastcgi manager that is only for PHP and can be downloaded in http://php-fpm.org/download. PHP-FPM is actually a patch of PHP source code designed to integrate FASTCGI process management into a PHP package. It must be patch into your PHP source code and can be used after compiling and installing PHP. Now we can download in the latest PHP 5.3.2 source tree to directly integrate the PHP-FPM branch, it is said that the next version will be fused into the main branch of PHP. Relative SPAWN-FCGI,PHP-FPM has a better control over CPU and memory,
And the former is prone to collapse and must be monitored with crontab, while PHP-FPM does not have this annoyance. PHP5.3.3 has integrated php-fpm, no longer a third-party package. PHP-FPM provides a better way to manage the PHP process, effectively controlling memory and processes,
can be smooth overloaded PHP configuration, than spawn-fcgi have a bit more, so by the official PHP included. The PHP-FPM can be turned on with the –ENABLE-FPM parameter when the./configure. NGINX+FASTCGI operating principle Nginx does not support the direct invocation or parsing of external programs, all external programs (including PHP) must be called through the FastCGI interface. The FastCGI interface is a socket under Linux,
(The socket can be either a file socket or an IP socket). In order to invoke a CGI program, you also need a fastcgi wrapper (wrapper can be understood as the program used to start another program),
This wrapper is tied to a fixed socket, such as a port or a file socket. When Nginx sends the CGI request to the socket, through the FastCGI interface, wrapper accepts the request,
A new thread is then derived, which invokes the interpreter or an external program to process the script and reads the return data, and then wrapper the returned data through the FastCGI interface.
Passed to nginx along a fixed socket, and finally, Nginx sends the returned data to the client, which is the whole process of nginx+fastcgi operation. The detailed process, as shown in:

CGI FASTCGI 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.