Home  >  Article  >  Backend Development  >  The relationship between cgi, fast-cgi and php-fpm (with flow chart)

The relationship between cgi, fast-cgi and php-fpm (with flow chart)

藏色散人
藏色散人forward
2022-10-08 14:07:113158browse

The relationship between cgi, fast-cgi and php-fpm (with flow chart)

First let’s talk about CGI

  • cgi is a protocol and has nothing to do with the process. For example, the web server (nginx) receives a PHP network request. At this time, nginx needs to find the PHP parser according to the configuration file. After simple processing, some of the requested information is handed over to the PHP parser. At this time, it is stipulated Which protocols should be transmitted, and in what format, this standard is called cgi protocol

  • #php explanation is the cgi program that implements this protocol, nginx hands these contents to php After the interpreter, it reads the initialization environment such as php.ini, then processes the data, and finally converts it into a data stream that conforms to this protocol and sends it to nginx, and finally returns it to the browser [Recommendation: PHP Video Tutorial]

fast-cgi manages cgi program

  • fast-cgi is a resident process program, and cgi is used for each The difference between a web request and a process is that fast-cgi will start multiple cgi programs at the same time when the web server starts, so that when a dynamic page request comes in, the data flow can be handed over to the fast-cgi process manager, so The advantage is that the web server can handle more requests and parse php.ini only once, which improves the response speed.

The diagram is as follows

The relationship between cgi, fast-cgi and php-fpm (with flow chart)

php-fpm manages cgi program

  • First of all, php-fpm is the product of integrating fast-cgi and adding some new functions. Since the fast-cgi program provided by the web server has many shortcomings when managing php-cgi, for example, if the configuration file of php.ini is modified, the web server must be restarted to make it take effect (php-cgi cannot start smoothly and kills PHP cannot work normally when using php-cgi), these problems can be solved when using php-fpm

The flow chart at this time is as follows

The relationship between cgi, fast-cgi and php-fpm (with flow chart)

The above is the detailed content of The relationship between cgi, fast-cgi and php-fpm (with flow chart). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete