This article was also published in HTTPS://GITHUB.COM/ZHANGYACHEN/ZHANGYACHEN.GITHUB.IO/ISSUES/88
On the understanding of the gateway, one sentence is: As a translator, abstract out a way to reach the resources.
This refers to the use of the translator to reach the resources, can include the Conversion Protocol (HTTP/FTP) to obtain the other end of the gateway with the client using a different protocol server resources, can also include through the gateway to the database to send query statements to obtain dynamic data, can also include through the gateway and different networks to communicate. In short, resources are obtained through the gateway.
After understanding the macro concept of the gateway, let's look at the classification of the gateway:
The gateways above are both client-and server-side gateways, which are located in the middle of the server and client. There is also a common gateway, an application server, that combines the target server with the gateway in a single server. For example, the client connects to the server via HTTP, and the server sends the request through a gateway application programming interface to the application running on the server.
The first popular Application Gateway API is the Universal Gateway Interface (Common Gateway interface,cgi). CGI is a standard set of interfaces . For example, when the server needs to request the resources of the gateway, it passes the required data to it (usually the entire request, including the URL, the query string, the header of the HTTP request, etc.). The gateway then returns the response data to the server and the server returns the data to the client.
So, the nature of CGI is: A protocol that includes input requests, referrals, and responses.
But there is one obvious problem with CGI: A new process is raised for each CGI request, and the overhead is limiting the performance of those using the CGI server. So a new kind of cgi--fastcgi appeared.
The FastCGI interface simulates CGI, but runs as a persistent daemon. First, fastcgi initiates a master, parses the configuration file, initializes the execution environment, and then starts multiple workers. When the request comes in, master passes it to a worker, and then immediately accepts the next request.
The above-mentioned CGI and fastcgi are protocols that are not related to a particular language.
So what is php-cgi? There are 2 main types of statements online:
The personal understanding is: php-cgi is PHP comes with the fastcgi manager, the management process name is php-cgi, it should be the name of the coincidence.
But the php-cgi's shortcomings are:
In summary, the birth of the PHP-FPM, but also a realization of the FASTCGI protocol procedures. PHP-FPM provides a better way to manage PHP processes, effectively controlling memory and processes, and smoothing the overloading of PHP configurations.
Reference: How to explain the relationship between CGI, FastCGI and php-fpm in a popular way?
Concept understanding: cgi,fastcgi,php-cgi and PHP-FPM
HTTP Authoritative Guide 8.1 8.2 8.3
Gateway php-cgi fastcgi PHPFPM