Home > Article > Backend Development > A brief discussion on the principles and concepts of cgi, fastcgi and php-fpm
This article mainly talks about the principles and concepts of cgi, fastcgi and php-fpm. Interested friends can learn about it.
cgi is the common gateway interface definition. When the web server receives the request for /index.php, it will start the corresponding CGI program, which is the PHP parser. Next, the PHP parser will parse the php.ini file, initialize the execution environment, process the request, return the processed result in the format specified by CGI, and exit the process. The web server then returns the results to the browser.
fastcgi is a protocol. Realize the management process and improve cgi performance. Standard cgi will parse php.ini for each request and initialize the environment, which is a waste of time; fastcgi starts the master process, parses the configuration file, initializes the environment, and then starts multiple worker processes; when the request comes, the master Pass it to the workers for processing; if there are not enough workers, a few will be added in advance, and if there are many workers, a few will be stopped.
is a program that implements the fastcgi protocol. After modifying php.ini, the php-cgi process cannot restart smoothly. php-fpm's handling mechanism for this is that new workers use new configurations, and existing workers can rest after processing the work at hand. This mechanism is used to smooth the transition.
Related tutorials: PHP video tutorial
The above is the detailed content of A brief discussion on the principles and concepts of cgi, fastcgi and php-fpm. For more information, please follow other related articles on the PHP Chinese website!