Nginx parses the principles of PHP, cgi/fastcgi and php-fpm relationships.
First, the scene that Php+nginx came into being.
With the development of the Internet, the user accepts a wide range of this, the increase in data flow makes the web end of the running load pressure increasing, savage growth in the big Data era of the Web language PHP also found more superior than old partner Vitality partner Nginx, said Nginx we will be a chatter of the mystery.
From the following several dimensions to analyze the vitality of nginx, of course, and parsing PHP old partner Apache compared to.
- Performance
1.1 Less resource share, save memory resources
1.2 The non-blocking request processing mechanism adds a strong power to it, which is why it is possible to keep a golden gun in a high-burst toss. haha ~
1.3 There is a lot of information about the same performance than Apache Upgrade 3 times times, this piece does not agree.
- Ductility
2.1 High-poly modular design, the introduction of the module written to make the product more attractive and dynamic
2.2 There are active technical communities and technical groups to facilitate the support of technology.
- Magnitude and availability
3.1 Lightweight
3.2 Parsing a static page is far better than parsing a dynamic page.
3.3 Configuration More concise and friendly, quit the bloated. The drawback is that URL rewriting is still to be enhanced.
3.4 Emerging means that there are stability challenges and gug accompanying, of course, there is no need to worry about, there are predecessors paving the road.
Second, what is CGI, what is fastcgi, what is php-fpm, what is php-cgi
CGI: is a scalable, high-speed interface for communicating between HTTP server and dynamic scripting languages
FastCGI: is the fast version of CGI (haha, haste version) most popular HTTP servers support FastCGI, including Apache, Nginx and Lighttpd and so on, this area fast can be very amazing:
1. Performance improvements. His father encountered a dynamic script parser when processing a request.
2. The upgrade comes with support for high burst
3. Security Upgrade
said performance improvement, there must be a way to improve the performance, what is the principle of ascension? The
1.1 interface processing mode uses the C/s structure. In the processing mechanism, the HTTP service and the script parser are stripped away, so that the deployment becomes separable, so that the script parsing server can be divided into multiple daemons, and the dynamic script is distributed to FASTCIG, the results will be given back to the browser. The HTTP server is a self-absorbed work of dry static resource parsing. This is equivalent to the concept of multithreading, of course, it will be fast.
PHP-FPM: This is the script parsing daemon we mentioned above.
php-cgi: Is the fastcgi manager that comes with PHP.
Iii. how Nginx parses PHP
Nginx is unable to parse the dynamic script, the following look at a schematic analysis of the picture, frankly, Nginx parsing PHP is through the FAST-CIG + PHP-FPM with the completion of.
When the user accesses the PHP page through the browser, the process is the first request to the Nginx server, the server discovery is a dynamic request, nginx through the fast-cgi interface to the dynamic script PHP communication, FAST-CIG under Linux is a socket (file or IP type), The communication process is initiated by the FastCGI wrapper (wrapper can be understood as the program used to start another thread) to start a CIG parser. WEB server sends CGI environment variables and standard input to fastcgi child processes php-cgi
After the fastcgi child process finishes processing, returns the standard output and error information from the same connection to the Web server and back to the user. 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, and during the php-cgi launch, there will be guardians or managers (PHP-FPM) to prevent php-cgi from collapsing.
So the whole process is finished.
Reprint http://blog.csdn.net/qq_36031499/article/details/53911906
The principle of Nginx parsing PHP | The relationship between CGI, FastCGI and PHP-FPM