What is CGI? CGI is a protocol, it doesn't matter what the process is. Web server, such as Nginx, is simply the publisher of the content.
For example, 1) If the request is/*.html static data, then Web server will go to the file system to find this file, sent to the browser. 2) If the request is/*.php Dynamic Data, Nginx according to the configuration file, need to find the PHP parser to deal with, then he will simply handle the request to the PHP parser.
What data will the Nginx send to the PHP parser? URLs, query strings, post data, HTTP headers all have. So, 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/*.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. The Web server then returns the results to the browser. 2. What is fastcgi?
Fundamentally, fastcgi is used to improve the performance of CGI programs. Similar to cgi,fastcgi can also be said to be a protocol.
FastCGI is like a resident (long-live) CGI, which can be executed all the time, so long as it is activated, it will not take a moment to fork once (this is the most notorious fork-and-execute mode of CGI). It also supports distributed operations where the FastCGI program can execute and accept requests from other Web servers on hosts other than the Web server.
FastCGI is a language-independent, extensible architecture for CGI open extensions whose main behavior is to keep the CGI interpreter process in memory and thus achieve high performance.
How fastcgi works 1) load the FASTCGI Process Manager (IIS ISAPI or Apache Module) at Web server startup 2) FASTCGI process Manager itself initializes multiple CGI interpreter processes (visible multiple php-cgi) and waits for a connection from the Web server. 3) When a client request arrives at Web server, the FASTCGI process manager selects and connects to a CGI interpreter. WEB server sends CGI environment variables and standard input to the FASTCGI child process php-cgi. 4) fastcgi the standard output and error information back to Web Server from the same connection after the child process finishes processing. When the fastcgi child process closes the connection, the request is processed to completion. The fastcgi child process then waits and processes the next connection from the FASTCGI process Manager (running in Web server). In CGI mode, php-cgi exits here.
In the above scenario, you can imagine how slow CGI is usually. Every Web request PHP must re-parse php.ini, reload all extensions, and initialize all data structures. With fastcgi, all of this occurs only once when the process is started. An additional benefit is that the persistent database connection (persistent connection) can work. 3. What is php-cgi?
PHP-CGI is a PHP interpreter, it is only a CGI program, can only parse the request, return the results, not process management. 4. What is PHP-FPM?
PHP-FPM is the FASTCGI process Manager, and for the specific implementation of the FASTCGI protocol, he manages a process pool to handle requests from the Web server. Currently, after the PHP5.3 version, PHP-FPM is built into PHP.
PHP-FPM Start-up:
/usr/local/php/sbin/php-fpm
PHP-FPM shutdown:
Pkill PHP-FPM
Or
Kill-int ' Cat/usr/local/php/var/run/php-fpm.pid '
Restart of PHP-FPM:
KILL-USR2 ' Cat/usr/local/php/var/run/php-fpm/pid '
To see if PHP-FPM started successfully:
NETSTAT-TUNPL | grep 90001 or
PS aux | Gerp PHP-FPM
Boot php-fpm:
Open/ect/rc.local Join/USR/LOCAL/PHP/SBIN/PHP-FPM
Signal: INT, term terminated immediately
QUIT Smooth Termination
USR1 Reopen log file
USR2 smoothly overloads all worker processes and reloads the log and binary modules