Web Services Nginx and PHP interrelationships

Source: Internet
Author: User
Tags fpm php web development dedicated server

Do not know the truth, only in this mountain, only to do PHP development to complete the business logic, may be trapped in the Web services of the mountain, are not aware of the operation of these services, mutual relations, especially if there is a dedicated server operations, it is more easy to ignore these things, today take time to do a summary.

In the local development time because it is used Windows system, install the integrated development environment XAMMP, click a few Start button can be PHP Web development, fool-like operation of course convenient, but if completely rely on the fool-type operation, the future may become a real fool.

The server is using a Linux system, using MySQL + nginx +php to implement Web services, now to look at these several services, and then look at the relationship between the several services.

Nginx and PHP

What does Nginx have to do with PHP and how does it relate? How to run a PHP program to provide services to the client via Nginx?

To put it simply, Nginx,nginx is a Web service that supports HTTP protocols, can receive HTTP requests from clients, is the gateway to client browsing requests, and Nginx is like a communications department that provides processing of client HTTP requests.

And then say it. php,php is a programming language that enables Web applications to make a variety of pages in real time, in accordance with customer needs. PHP is also likened to a section, PHP is a page authoring department, but the PHP department itself does not directly accept the client HTTP request.

In this way, the relationship between the two is clear, Nginx is the customer HTTP request entry and exit, received a customer request, forwarded to the PHP department, tell the PHP department customers need what kind of Web page, PHP just follow the request to parse generate the corresponding page, and then handed back to Nginx.

The above is a metaphor to illustrate the approximate flow of the relationship, but the actual details of course to be more complicated, because it is not easy to use programming language to achieve these relationships.

In reality, if there are two departments need to cooperate, usually need intermediate docking person, then here is the middle docking person who? This is the first to mention the CGI (Common G), CGI is the implementation of the Web server Communication Standard specification (here and Nginx Standard specification), the specification clearly pointed out the two sides of the exchange need to give what parameters, as well as the format of parameters, etc. Follow this set of specifications of the scripting language can interact with the Web server, but deal with more, need to consider the efficiency problem, and then the upgrade, and then have a fastcgi, the efficiency is relatively high, and suitable for PHP and Nginx docking is PHP-FPM, PHP-FPM is a PHP (Web application) to the Web Server FastCGI Protocol interface program, which can be understood as nginx and PHP communication between the middleman, each time the Nginx received an HTTP request, will look at the file name, If the discovery is a PHP file, according to the requirements and php-fpm interaction, the corresponding parameters submitted to the past, PHP-FPM received parameters, the corresponding parsing, returned to the HTML page, the Nginx received data, and then return the data.

, my web server still sees many PHP-FPM processes without anyone's access, and the first php-fpm is the master process, which feels like a boss with a bunch of little boys on standby ready to work, when the Nginx receives the request, The corresponding parameters to PHP-FPM master process, that is their eldest brother, the eldest brother received something and put the live to other php-fpm, as for why to do so again, is because PHP did not complete a work, all to the initial session, read the configuration file, and then start, work, Since every time before the preparation of the work is the same, then this will certainly result in a waste of efficiency, so there is a master process to help you prepare the work, and then received the request to the other php-fpm, and can dynamically control the number of other php-fpm, Here I try to kill a few php-fpm process, found that there is a new php-fpm out. To adjust the number of these processes, you can modify the optimizations in php-fpm.conf.

Web Services Nginx and PHP interrelationships

Related Article

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.