nginx - I have a question about the running process of PHP-CGI. Please solve it.
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 17:23:26
0
3
726

I have some doubts about the usage process of php-cgi, please help me solve it.

The hypothetical scenario is as follows:
nginx monitors 192.168.1.101:80, no php environment
index.php 192.168.1.101::/dev/shm/index.php
php-fpm monitors 192.168.1.102:90000

The confusion is, during the running process, index.php is parsed and run on 192.168.1.101, or is it sent to 192.168.1.102 for parsing and running? Can any expert explain the detailed process?

If it is parsed and run in 1.102, once a relatively large code package such as phar or a single large php file is encountered, is the entire package sent together? Doesn’t the intranet traffic look impressive?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(3)
仅有的幸福

Nginx that monitors 192.168.1.101:80 distributes PHP requests to 192.168.1.102:9000 that PHP-FPM monitors through fastcgi_pass. PHP-FPM parses the parameter $_SERVER['SCRIPT_FILENAME'] passed by Nginx according to the Nginx request. PHP file, the PHP interpreter inside the PHP-FPM worker process executes the script and returns the result to Nginx through the LAN.

TCP network communication is used between Nginx and PHP-FPM processes, while MOD_PHP, which integrates the PHP interpreter as a module into the Apache process (thread), is completely different. Through Nginx's upstream, it is easy to implement PHP -FPM clustering and high availability.

Also:
Apache can be used with PHP-FPM through the mod_fastcgi module. In this case, it is recommended that Apache use event MPM, a multi-process, multi-threaded epoll event-driven MPM. PHP-FPM uses the default non-thread-safe version, which is more efficient and stable.
Apache can be used with PHP-CGI through the mod_fcgid module. It is recommended to use the same method as above.
Note that Apache's mod_fastcgi module is similar to the fastcgi support provided by Nginx. Its function is different from mod_fcgid and more efficient than mod_fcgid, because mod_fcgid needs to manage the PHP-CGI process by itself, while under mod_fastcgi, the PHP-FPM main process manages its own FPM work. Process.

Peter_Zhu

Thanks to @白一子 and @eechen for their answers. In fact, when I ask this question, I want to know whether a php script needs to be installed on the machine 192.168.1.102. Because I mainly used apache before and rarely used php-fpm~

I just found two servers to set up the environment, and I probably understand it.

In fact, php-fpm only receives the header from nginx, which is fastcgi_param, and then finds SCRIPT_FILENAME, loads the script from 1.102's own hard disk and executes it, which is the process of transmission between nginx and php-fpm. It is just the header and has nothing to do with the script. , and then execute the php code through the header like apache~

In other words, regardless of other advanced functions and internal operating principles of apache, the running processes of nginx + php-fpm and nginx + apache are basically the same~~

仅有的幸福

This, I have already given the answer in the question /q/1010000002753412. The flow chart is given in my answer, it should be easy to understand

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!