The difference between CGI and FastCGI

By XiaoXin
A Bit Randomly

The @counter-style at-rule in CSS allows you to define custom counter styles, which control the appearance of counter elements in your document. A counter style consists of several components, including a name, algorithm, ... Read What Is @counter-style In CSS

Main Contents

The difference between CGI and FastCGI

CGI was used a lot in 2000 or earlier. In the past, web servers generally only processed static requests. According to the content of this request, the web server would fork a new process to run external c programs (or Perl scripts. ..), this process will return the processed data to the web server, and finally, the web server will send the content to the user, and the fork process just now will also exit. If the user also requests to change the dynamic script next time, the web server will fork a new process again, and it will go round and round.

Later, a more advanced way appeared, the web server can have a built-in Perl interpreter or PHP interpreter. That is to say, the way these interpreters are made into modules, the web server will start these interpreters when it starts. When a new dynamic request comes in, the web server parses these Perl or PHP scripts by itself, saving the need to re-fork a process and improving efficiency.

The way of FastCGI is that when the web server receives a request, it will not re-fork a process (because this process starts when the web server starts and will not exit), and the web server directly passes the content to this process (process Inter-communication, but FastCGI uses another method, TCP communication), this process processes the request after receiving it, returns the result to the web server, and finally waits for the next request instead of exiting. 

CGI forks a new process to process, read parameters, process data, and then end the life cycle.

FastCGI uses TCP to establish a connection with the process on the remote machine or the local process. To open the TCP port, enter a loop, wait for the arrival of data, and process the data.

For example, the server now has 100,000 words, and the client will send a string every time, asking how many words are prefixed with this string. Then you can write a program that will build a trie tree, and then you can go directly to this trie to find it every time the user requests it. But if the CGI method is used, the class trie will be gone after the request ends, and when the process is started next time, a new trie tree will be created, which is too inefficient. In the FastCGI method, the trie tree of this class is established when the process starts, and the specified prefix can be directly queried on the trie tree in the future.

Continuing...

Please Share This Article Thank You!

Parts of Top Latest PHP Interview Questions And Answers For Experienced
Linux Select, Poll and Epoll difference

selectpollepoll select Select first appeared in 4.2BSD in 1983. It monitors an array of multiple file descriptors through a select() system call. When select() returns, the ready file descriptors in the array will be modif...

Advantages and Disadvantages of Apache and NGINX server

Advantages of Nginx over apacheAdvantages of apache over Nginx Comparison of the advantages and disadvantages of Apache and Nginx Advantages of Nginx over apache Lightweight, occupying less memory and resources than apache...