The principle of combination of nginx and PHP in LNP environment

Source: Internet
Author: User

is understanding, access to information, coupled with self-understanding, to draw conclusions, if there are errors, please correct me ....

LNP environment, Nginx and PHP working together to explain the principle:

Before the internet era, we become web1.0 era, when users are passively accept network information, what you see on the server, you can not upload things to the server, and mainly static files mainly, almost no dynamic program, so nginx processing is easy. But with the motherland's strong, the Times and the progress of technology, the advent of the web2.0 era, the user-oriented, dynamic language is also popular, such as PHP, Java, etc., so the dynamic request on the network up, but Nginx can not handle the dynamic request, so the accompanying dynamic program parser came into being , PHP parser, Java parser, and so on, but the question came, how can nginx to accept the dynamic request to the parser? How does the parser return to Nginx after processing? So there is the CGI (Common Gateway Interface) Universal Gateway Interface, through this interface to achieve the communication between the two, how to communicate it?

CGI feature is that every request to start the parser, fork a process to parse, after the completion of the process to kill, every time is such, it can be imagined that not only waste system resources, but also unable to deal with high concurrent requests, can not meet the web2.0 era of the vast number of netizens. So fastcgi out, a look at the name is relatively fast, he fork after the process does not kill, keep down so that the next use, efficiency is much higher.

Then how nginx through this interface to achieve communication, Nginx has a fastcgi module, nginx through the fastcgi to listen to the PHP program to run the address and port, when there is a dynamic program to access Nginx, Nginx through the fastcgi_pass thrown to PHP processing , the PHP processing is completed and returned to Nginx via the FastCGI interface, then the Nginx is returned to the user. So what does PHP do with it?

When PHP receives the dynamic program thrown by Nginx, the first is PHP-FPM (PHP fastcgi process Manager) PHP fastcgi Process Management received, then he calls a wrapper thread to activate the PHP parser, The dynamic request is parsed to the OP code (opcode) for processing, and the result is returned to PHP-FPM, which is returned to the user.

The principle of combination of nginx and PHP in LNP environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.