Current common PHP 4 kinds of operating modes
- CGI Common Gateway Interface Mode
- FAST-CGI mode
- CLI command line mode
- Module mode
Run mode
CGI Common Gateway Interface Mode
Each user has a request, will first create a child process cgi, and then processes the request, after the end of this process the child process
cgi is a web server to ensure that the data is transmitted over a standard format Common Gateway Interface Protocol
Older, more primitive, most of them do not have a
FAST-CGI mode
Is an upgraded version of cgi, FastCGI CGI like a type of permanent (long-live), it can always perform with, as long as the activation, will not always have to take the time to fork again, but also a protocol
FastCGI works are:
(1), load FastCGI Process Manager Web Server start when the [PHP FastCGI Process Manager is a PHP-FPM (php-FastCGI Process Manager)] (IIS ISAPI or Apache Module);
(2), FastCGI process manager initializes itself, to start multiple CGI interpreter process (php-cgi.exe more visible in the Task Manager) and waits for a connection from the Web Server.
(3) When a client request arrives Web Server, FastCGI Process Manager to select and connect to a CGI interpreter. Web server sends to the child FastCGI php-cgi CGI environment variables and the standard input.
(4), FastCGI child process after the completion of treatment standard output and error messages from the same connection returns Web Server. When the child FastCGI process closes the connection request will come to complete the process. FastCGI child process then waits for and FastCGI process manager process from the lower (running in the WebServer) is connected. In the normal mode, CGI, php-cgi.exe here will quit.
In CGI mode, CGI usually imagine how slow. Each Web request must be re-parse PHP php.ini, reload all dll extension and try to initialize the entire data structure. Use FastCGI, all of which occur only once when the process started. An additional benefit is that persistent database connections (Persistent database connection) can work.
CLI command line mode
This mode will be used to invoke the script is generally used to view information php
php -r "phpinfo ();" | less pagination
Module mode
- Apache + mod_php
- lighttp + spawn-fcgi
- nginx + PHP-FPM
Operating principle
PHP-CGI: fast-cgi is an agreement, and php-cgi process is to achieve such an agreement. But such comparisons rotten. It is a single process, a process of processing a request, after the end of treatment process will be destroyed
PHP - FPM: improved version of php-cgi, which directly manage multiple php-cgi process / thread. In other words, php-fpm is php-cgi process manager so it can be considered to achieve fastcgi protocol
running php principle, that is, at server startup, automatically load the PHP-FPM Process Manager to manage multiple PHP- CGI process to prepare response to user requests, as shown below:
Since php-cgi is loaded with server starts, it only happens once initialize variables
The difference between operating modes and operating principles
A plurality of operating modes corresponding to different inlets, the operating principle is fixed routes after entering the supermarket in the supermarket, by entering different modes of operation to the bottom (to enter the supermarket)