How Nginx and PHP-FPM communicate.

Source: Internet
Author: User
Tags fpm

FastCGIPrinciple
FastCGI is an application of httpserver and dynamicscripting languageCommunication interfaces, most popular HTTP servers support FASTCGI, including Apache, Nginx, and lighttpd. At the same time, fastcgi is also manyscripting languageSupport, there is PHP.
FastCGI interface Mode adoptsC/Sstructure, you can separate the HTTP server from the script resolution server and start one or more script parsing daemons on the script resolution server. Each time the HTTP server encounters a dynamic program, it can be delivered directly to the fastcgi process to execute, and the resulting results are returned to the client. This approach allows the HTTP server to handle static requests exclusively or return the results of the dynamic script server to the client, which greatly improves the performance of the entire application system.

NGINX+PHP-FPM Implementation principle

Nginx itself will not parse PHP, terminal to PHP page request will be to the fastcgi process to listen to the IP address and port, by PHP-FPM as a dynamic resolution server processing, and finally return the processing results to nginx. In fact, Nginx is aReverse ProxyServer. Nginx throughReverse ProxyThe function will move the dynamic request to the backend php-fpm, so as to achieve the parsing support of PHP, this is the Nginx implementationPHPDynamicThe principle of parsing.

Nginx does not support direct invocation or parsing of external programs, and all external programs (including PHP) must be called through the FastCGI interface. The FastCGI interface is a socket under Linux (the socket can be either a file socket or an IP socket). In order to invoke a CGI program, you also need a fastcgi wrapper (wrapper can be understood as the program used to start another program), which is bound to a fixed socket, such as a port or a file socket. When Nginx sends the CGI request to the socket, through the FastCGI interface, the wrapper receives the request, and then derives a new thread, which invokes the interpreter or the external program to process the script and reads the return data; The wrapper then passes the returned data through the FastCGI interface, passing it to nginx along a fixed socket, and finally, Nginx sends the returned data to the client.


This article is from the "11736718" blog, please be sure to keep this source http://11746718.blog.51cto.com/11736718/1876253

How Nginx and PHP-FPM communicate

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.