FastCGI is a binary network protocol for connecting an application server to a web server. FastCGI is similar to the Common Gateway Interface (CGI), but is designed to circumvent its performance issues.
Difference to CGI
When a CGI-based website is accessed, the web server starts a process of the CGI program and terminates it at the end of the request. Because CGI programs are often written in a scripting language such as Perl, this means that the often quite large interpreter has to be loaded per page view, which means a lot of overhead (the interpreter takes longer to load than the actual program execution for simple CGI programs). In addition, each request needs its own interpreter, which means that if there are several parallel requests, there are several copies of the interpreter in the server’s working memory.
While CGI is widely used due to its simplicity, independence from the programming language, and extensive support from virtually all web servers, the aforementioned overhead leads to high latency and quickly becomes overloaded on busy servers.
---
In contrast, with FastCGI, the program to be executed (including interpreter, if necessary) is loaded only once and is then available for multiple requests – whether from the same client or from different clients. Communication with the web server does not take place through environment variables and standard input/output, but via Unix domain sockets or TCP network connections, i.e. the program can even run on another computer.
In terms of programming, the difference to CGI programs can be seen in the fact that a FastCGI program has a central loop that receives requests and can run as long as the web server:
1 2 3 4 5 | use FCGI; $var = 'foo'; while (FCGI::accept () >= 0) { ... http-Request ... } |
During the loop, variables are preserved in the memory, which on the one hand allows for further optimization possibilities compared to CGI programs, and on the other hand requires more careful programming to avoid memory leaks.

How it Works
Communication with the web server is packet-oriented and connectionless. A data packet contains in the header:
- the FastCGI protocol version
- the type of message; largely corresponds to the data sources known from CGI – a packet can transport, among other things:
- the CGI environment variables
- the content of the standard input (for POST), or
- the content of the standard output (for output to the client)
a request ID and - the length of the following data.
Multiple clients can be served at the same time, as they can be distinguished by the request ID; therefore, in contrast to CGI, only one program instance is required to serve many clients.
Tagged With along77x , https://thecustomizewindows com/2024/05/what-is-fastcgi-what-is-the-difference-to-cgi/