What is the relationship between fastcgi and CGI in PHP, and what is fastcgi

Source: Internet
Author: User

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.
How the FastCGI works is:
(1) The FASTCGI process Manager itself initializes, launches multiple CGI interpreter processes (multiple php-cgi processes), and waits for a connection from the Web server. In this article, you use the PHP-FPM process Manager to start multiple php-cgi fastcgi processes. When you start the php-cgi fastcgi process, you can configure both TCP and UNIX sockets to start.
(2) When a client request arrives at the Web server (Nginx), the Web server forwards the request to the FASTCGI master process using the TCP protocol or the UNIX socket, fastcgi the main process to select and connect to a CGI interpreter (child process). The Web server sends CGI environment variables and standard input to the FASTCGI child process php-cgi.
(3)
FastCGI the standard output and error information from the same connection back to the Web server (Nginx) after the child process finishes processing.
When the fastcgi child process closes the connection, the request tells the processing to complete. The fastcgi child process then waits and processes the next connection from the FASTCGI process manager. In general CGI mode, php-cgi exits here.
So, you can imagine how slow the normal CGI mode is. Every Web request PHP must re-parse php.ini, reload all extensions, and reinitialize all data structures. With fastcgi, all of this occurs only once when the process is started. An additional benefit is that the persistent database connection (persistent connection) can work.
Advantages of PHP FastCGI:
(1) PHP scripts run faster. The PHP interpreter is loaded into memory without having to read from memory every time it is needed, which greatly improves the performance of running the site on a script.
(2) Less system resources are required. Because the server does not need to load PHP interpreter every time, you can increase the transfer speed of the site rather than increase the CPU burden.
(3) There is no need to make any changes to the existing code. The program that runs on apache+php can be applied to PHP FastCGI without modification.

What is the relationship between fastcgi and CGI in PHP, and what is fastcgi

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.