I. What is FastCGI
FastCGI is a scalable, high-speed interface for communication between HTTP servers and dynamic scripting languages. Most popular HTTP servers support FastCGI, including Apache, Nginx, and lighttpd. At the same time, FastCGI is also supported by many scripting languages, including PHP.
FastCGI evolved and improved from CGI. The main drawback of the traditional CGI interface is poor performance, because every time the HTTP server encounters a dynamic program it needs to restart the script parser to perform parsing, and then the result is returned to the HTTP server. When handling high-concurrency access, this is almost unusable. Additionally, the traditional CGI interface method has poor security and is now rarely used.
The FastCGI interface method uses a C/S architecture, allowing the HTTP server and the script parsing server to be separated, while starting one or more script parsing daemon processes on the script parsing server. Whenever the HTTP server encounters a dynamic program, it can directly deliver it to the FastCGI process for execution, and then return the obtained result to the browser. This method allows the HTTP server to focus on handling static requests or returning the results of the dynamic script server to the client, which greatly improves the performance of the entire application system.