PHP generally has three ways to work under Apache: Cgi,apache module, FastCGI
in CGI mode, if a user requests a PHP file, the Web server invokes the PHP parser to parse the file and then is returned to the client. Span style= "FONT-SIZE:16PX;" >
In Apache module mode, the PHP parser is used as a module of Apache so that the PHP parser works with the Web server.
in fastcgi mode, the Web server does not start a new process every time, like CGI, but instead passes the content to an existingApproached (this process is turned on when the Web server is started and does not exit), the process will process requests from the client over and over again.
1. CGI mode vs. module mode:
The difference between these two ways of working:
In CGI mode, if the client requests a PHP file, the Web server invokes the PHP parser to interpret the file, and then returns the result of the interpretation to the client in the form of a Web page, and in a modular (DLL), PHP is started and run with the Web server.
So from a certain point of view, the Apache module installed PHP has better security than CGI mode and better execution efficiency and speed.
2. fastcgi run mode analysis:
How the FastCGI works is:
(1), Apache boot loaded FastCGI process Manager "PHP FastCGI process Manager is PHP-FPM (php-fastcgi processes manager)."
(2), the FASTCGI process manager itself initializes, initiates multiple CGI interpreter processes 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) After the fastcgi process finishes processing, the standard output and error messages are returned from the same connection to the Web Server. When the fastcgi child process closes the connection, the request is processed to completion. The fastcgi child process then waits and processes the manager from the FASTCGI process (runningThe next connection in webserver). In the normal 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 DLL 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.
Resources:
http://fifiole.blog.163.com/blog/static/169459225201222962651804/
http://blog.csdn.net/ajaxuser/article/details/5892630
HTTP Service (v) how--php works in Apache