| 1 cgi (1) What is cgi:cgi (Common Gateway Interface) Public Gateway Interface, is one of the most important technology in WWW technology, has irreplaceable important position, CGI is external application (CGI program) The interface standard between Web servers is the protocol for passing messages between CGI programs and Web servers. The CGI specification allows the Web server to execute external programs, send their output to a Web browser, and CGI to turn a simple set of hypermedia documents from the Web into a complete new interactive media. (2) CGI purpose: CGI is to ensure that the data passed by the Web server is in standard format, convenient for CGI program writers. (3) CGI processing: Web server (Nginx, for example) is only the publisher of the content. For example, if the request/index.html, then the Web server will go to the file system to find this file, sent to the browser, here is distributed static data. If the request is/index.php, according to the configuration file, Nginx know that this is not a static file, need to find a PHP parser to handle, then it will be simple processing of the request to the PHP parser. Nginx will pass those data to (such as URL, query string, post data, HTTP header) PHP parser it? CGI is the protocol that specifies what data to pass, in what format, to the rear to handle the request. When the Web server receives the/index.php request, it launches the corresponding CGI program, which is the parser for PHP. The PHP parser then parses the php.ini file, initializes the execution environment, then processes the request, and then returns the processed result in a format specified by the CGI, exiting the process. Web server returns the results to the browser (4) CGI function Description: The vast majority of CGI programs are used to interpret the input information from the form, and to generate the corresponding processing on the server, or to feed the corresponding feedback to the browser. CGI programs are web pages with interactive functions (5) Summary: Over the above, CGI is a protocol, not related to the process or anything 2 FASTCGI (1) The role of Fastcgi: Fastcgi is used to improve the performance of CGI programs. (2) CGI program performance problem: "PHP parser will parse the php.ini file, initialize the execution environment", this is it. The standard CGI performs this step for each request (not too tired!). Start the process very tired to say! ), so the time to process each request will be longer, which is obviously unreasonable! (3) What fastcgi is doing: Managing the process first fastcgi willStart a master, parse the configuration file, initialize the execution environment, and then start multiple workers. When the request comes in, master passes it to a worker, and then immediately accepts the next request. This avoids duplication of labor, and efficiency is naturally high. And when the worker is not enough, master can pre-boot several workers according to the configuration and so on, of course, the idle worker too much, will also stop some, this improves the performance, also saves the resources. This is FastCGI's management of the process 3 php-fpmphp parser is php-cgi. PHP-CGI is just a CGI program, his own can only parse the request, return results, not process management, so there are some can dispatch php-cgi process, and PHP-FPM is able to dispatch php-cgi process of a program. PHP-FPM after a long period of development, gradually get everyone's approval php-fpm is actually a patch of PHP source code, designed to integrate FASTCGI process management into the PHP package. It must be patch in your PHP source code before it can be used after compiling and installing PHP. PHP5.3.3 has inherited php-fpm and is no longer a third-party package. PHP-FPM provides a better way to manage PHP processes, can effectively control memory and processes, can be smoothed overloaded PHP configuration 4 Summary (1) CGI is a public gateway interface that works in a process way. That is to create a CGI process when requested, close the CGI process at the end of the application and exit the memory (2) fastcgi is the development of CGI, when the application ends, the fastcgi process does not exit memory, but waits for the next request. PHP's CGI mode is the fastcgi way, in the PHP4 is this (3) PHP-FPM is the fastcgi manager. Prior to this, the fastcgi process is managed by the operating system, and once a fastcgi process fails, It is possible for the operating system to run normally. PHP-FPM's role is to create a fence between the operating system and the fastcgi, thus blocking the transmission of the fastcgi fault to the operating system. |