A concept:
Cgi
CGI (Common Gateway Interface), Universal Gateway interface. The protocol used when interacting between Web servers (such as Nginx) and script parsers (such as php-cgi). It specifies how the data such as the requested URL, HTTP header, post data should be passed to the script parser in what format, and what format the script parser should return the HTTP response.
FastCGI
FastCGI is an upgraded version of the CGI protocol. The standard CGI for each request will parse through the corresponding script configuration file (such as php.ini), load the configuration and extension, initialize the execution environment, the performance is very poor. FastCGI adopts Master-worker mode and resident memory strategy, which improves the response speed.
php-cgi
php fastcgi implementation, but also as PHP script parser is responsible for running PHP script, the disadvantage is that the process management scheduling is poor.
php-fpm
For managing and scheduling php-cgi processes, similar to spawn-fcgi
Two principles
understand the workflow of normal CGI first:
Web server receives a user request and submits the request to a CGI program, which is processed according to the parameters submitted by the request. The output standard HTML statement is then returned to the Web Server,web server and returned to the client, which is how the common CGI works.
from the above, CGI is only a dynamic Web page, which is characterized by every request, Web server fork out a separate CGI program process to process, the advantage is that the web The server and the specific program processing independently, the structure is clear, the controllability is strong, at the same time the disadvantage is that if in the case of high access requirements, CGI process fork will become a very large server burden, imagine hundreds of concurrent requests cause the server fork out hundreds of processes to understand. This is why CGI has been saddled with poor performance and high resource consumption for notoriety reasons.
The corresponding problem has a solution, the current popular scenario is the use of modular design, basically the current Web server has a corresponding module mechanism to expand its functionality, as long as the design specifications of the module designed by, can be inserted into the web The server itself processes the process, so the performance is greatly improved, such as the Isapi,apache DSO of IIS. However, this method is not without shortcomings, for example, for different Web servers, to be developed according to different standards, can not do webserver independence; For example, this will be the input validation of the work to the Web server, there is no way to handle it, for example, if the problem will affect the entire web The server processing process, such as the insertion of a Web server process, cannot run with multi-user marks, cannot handle virtual host permissions, and so on.
Fortunately, we have another option, this is fastcgi. FASTCGI is a CGI-based extension, and his core idea is to build an intelligent, sustainable middle tier between Web server and specific CGI programs that governs the operation of CGI programs so that Web server simply submits the request to this layer. This layer then derives several reusable CGI program instances, and then distributes the requests to these instances, which are controllable, sustainable, reusable, so that the process is not repeatedly fork, on the other hand can be monitored through the middle layer control and detection mechanism to monitor the operation of these instances, According to different conditions fork or recycling examples, to achieve flexibility and stability for both purposes.
Three PHP bottom working principle
http://blog.csdn.net/21aspnet/article/details/6973405
http://www.nowamagic.net/librarys/veda/detail/102/
The above describes the CGI php-cgi,php underlying principles, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.