cgi,fastcgi,php-fpm

Source: Internet
Author: User
Tags fpm

CGI (Common Gateway Interface)

CGI is the specification of external programs when the Web server is running, and programs written by CGI can extend server functionality. CGI applications can interact with the browser, and data can be obtained from the database server by communicating with external data sources such as database servers through the database API. When formatted as an HTML document, it is sent to the browser, or the data obtained from the browser can be placed in the database. CGI is supported on almost all servers, and CGI can be written in any language, including popular C, C + +, VB, and Delphi. CGI is divided into two types of standard CGI and indirect CGI. Standard CGI uses command line arguments or environment variables to represent detailed server requests, and the server communicates with the browser using standard input and output methods. Indirect CGI, also known as buffered CGI, inserts a buffer between the CGI program and the CGI interface, and the buffer program communicates with the CGI interface using standard input and output.

FastCGI
FastCGI 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-fpm
PHP-FPM is used in conjunction with the Nginx program, PHP-FPM is actually a fastcgi protocol to strengthen the implementation, has been included in the PHP kernel, can be enabled by the--ENABLE-FPM compilation option, PHP-FPM supports configuration smoothing changes (by fork new worker processes), good performance and high memory efficiency, which is why NGINX+PHP-FPM's configuration combination overrides apache+mod_cgi and apache+mod_php important reasons

Relationship
CGI for each HTTP request is fork a new process to handle, The process involves parsing the php.ini file, initializing the execution environment, and then returning the processed data to the Web server, and finally the Web server sends the content to the user, and the process of the fork exits. If the next time the user also requests dynamic resources, then the Web server again fork a new process, the cycle of progress.
FastCGI then fork a master, parse the configuration file, initialize the execution environment, and then fork multiple workers. When the request comes in, master passes it to a worker, and then immediately accepts the next request. This avoids duplication of labor, and efficiency is naturally high. And when the worker is not enough, master can pre-boot several workers according to the configuration and so on, of course, the idle worker too much, will also stop some, this improves the performance, also saves the resources. This is FastCGI's management of the process. Most FASTCGI implementations maintain a process pool.
CGI, fastcgi usually refer to the protocol specification of the WEB server communicating with the interpreter, while PHP-FPM is an implementation of the FASTCGI protocol.


Browser, Nginx, PHP-FPM (master)->php-fpm (PHP interpreter in worker), Nginx browser

cgi,fastcgi,php-fpm

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.