Nginx PHP fastcgi Installation

Source: Internet
Author: User
Tags php source code nginx server

The CGI name is a "public Gateway Interface" (Common Gateway Interface), a tool that the HTTP server "chats" with 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.

FastCGI is like a resident(long-live) typeCGI, it can be executed all the time, as long as the activation is notwill take time to fork each time (this is the most reviled CGI Fork-and-execute modelType). 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. nginx+fastcgi Operating principle
NgiNX does not support direct invocation or parsing of external programs, and 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), which is bound to a fixed socket, such as a port or a file socket. When Nginx sends a CGI request to the socket, through the FastCGI interface, wrapper accepts the request and derives a new thread, which invokes the interpreter or the external program to process the script and reads the return data; Wrapper the returned data through the FastCGI interface, along the fixed socket to nginx; Finally, Nginx sends the returned data to the client, which is the whole process of nginx+fastcgi. The detailed procedure is shown in 1.

spawn-fcgi and PHP-FPM

As described earlier, the FastCGI interface mode initiates one or more daemons on the script resolution server to parse the dynamic script, which is the FASTCGI process Manager, or the fastcgi engine, SP AWN-FCGI and PHP-FPM are the two fastcgi process managers that support PHP .
The following is a brief introduction of the similarities and differences between spawn-fcgi and PHP-FPM.

SPAWN-FCGI is part of the HTTP server lighttpd, and is now independently a project, typically used in conjunction with LIGHTTPD to support PHP, but ligttpd spwan-fcgi in high concurrent access, There will be a memory leak or even an automatic restart of the fastcgi problem.

Nginx is a lightweight HTTP server, you must rely on third-party fastcgi processor to be able to parse PHP, so the combination of nginx+spawn-fcgi can also implement the parsing of PHP, here is not too much to tell.

PHP-FPM is also a third-party fastcgi process Manager, which is developed as a patch for PHP, when installed also need to compile with the PHP source code, that is, PHP-FPM is compiled into the PHP kernel, so in the processing performance is more excellent And it is also much better at handling high concurrency than the spawn-fcgi engine, so it is recommended that this combination of nginx+php/php-fpm be parsed for PHP .

FastCGI's main advantage is to separate the dynamic language and HTTP server, so nginx and PHP/PHP-FPM are often deployed on different servers to share the pressure of the front-end Nginx server, so that nginx-only processing static requests and forwarding dynamic requests, and PHP /PHP-FPM Server-Exclusive parsing of PHP dynamic requests.

PHP-FPM is already part of PHP since php5.3.3 .

Http://book.51cto.com/art/201202/314842.htm

Nginx PHP fastcgi Installation

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.