PHP CGI FastCGI php-fpm FAQ

Source: Internet
Author: User
When a Web server accepts a request from a browser, it is returned directly to the browser if it is a static resource, and if it is a dynamic resource, CGI can be understood as a protocol or a class of handlers that can execute a php or Python script.

Web server exec Such a process, and then give him some input parameters, he slowly finished the results back to the Web server, and from the protocol level, the CGI protocol is to standardize the Web server and CGI program some of the input and output parameters meaning.

The CGI (Common Gateway Interface) was developed by the U.S. National Supercomputer Application Center (NCSA) for NCSA HTTPd WEB servers in 1993. The Web server uses the UNIX shell environment variable to hold parameters passed from the Web server, and then generates a separate process to run the CGI. The first implementation of CGI is written by Perl, but CGI has the following problems:

    • Inefficient: Each connected fork is processed by one process.
    • Very limited functionality: CGI receives only one request and outputs a response.

So there's the Apache mod_php,fastcgi (Fast Common Gateway Interface)

FASTCGI uses a process/thread pool to process a series of requests. These processes/threads are managed by the FASTCGI server, not the Web server. When a request comes in, the Web server passes the environment variable and the page request through a long socket connection to the fastcgi process. So fastcgi has the following advantages:

    • Performance: Bypass the overhead of CGI opening up new processes through the process/thread pool.
    • Compatible: Very easy to retrofit existing CGI standard programs.
    • Language-Independent: FastCGI is a set of standards, theoretically speaking, as long as the standard output (STDOUT) language can be used as the FASTCGI standard Web backend.

  • Web server isolation: The fastcgi back end and Web server run in different processes, and any failure of the backend does not cause the Web server to hang.
  • Patent: No intellectual property issues for private APIs such as Apache mod_php.
  • Extensions: fastcgi backend and Web server communicate through sockets, both distributed and easily scaled out.
  • 5.PHPFPM is a concrete implementation of PHP for FASTCGI, it will create a number of CGI sub-processes after the start, and then the main process is responsible for managing the child process, and it provides a socket externally, That Web server when you want to forward a dynamic request only need to follow the format required by the FASTCGI protocol to send data to this socket, that PHPFPM created by the child process to scramble for the socket connection, who grabbed who processed and returned the results to the Web server, What did the PHPFPM main process do? Let's say one of the sub-processes exits unexpectedly, and the PHPFPM will monitor him. Once a CGI subprocess is discovered, another one is started, and many other management functions

    6 PHPFPM as a standalone process exists through the socket to establish a connection with Nginx, while mod_php is loaded into the Apache server as a module, and both of them as CGI dispatch managers, they are not the same way to manage it

  • Related Article

    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.