For php-fpm and cgi, and the understanding of concurrent responses, php-fpmcgi
Reference link:
Https://www.zhihu.com/question/64414628What is the relationship between the number of php fpm processes and the number of concurrent processes?
-Https://segmentfault.com/q/1010000005942449/a-1020000012063637 php does not support multithreading so don't consider concurrency issues?
-Http://bbs.csdn.net/topics/390778072 PHP is single-threaded, how to deal with a large number of http access? # Layer-9 Answers
-Https://www.cnblogs.com/scott19820130/p/4915515.html PHP threads, processes and concurrency
-Https://segmentfault.com/q/1010000000256516 cannot figure out the relationship between FastCgi and PHP-fpm.
-Http://php.net/manual/zh/install.fpm.php FastCGI Process Manager (FPM)
-Https://www.cnblogs.com/PerkinsZhu/p/7242247.html multithreading (1) the relationship between high concurrency and Multithreading
First, understand the relationship between php-fpm and cgi.
Cgi is a data transmission protocol between the web server and cgi program (which can be understood as a php interpreter), ensuring that standard data is transmitted.
Php-cgi is the cgi program mentioned above.
Fastcgi is a solution/protocol used to improve the performance of cgi programs (php-cgi.
What are the performance problems of cgi programs? "The PHP parser parses the php. ini file and initializes the execution environment. The Standard CGI performs these steps for each request, so the processing time will be relatively long.
Fastcgi will first start a master, parse the configuration file, initialize the execution environment, and then start multiple workers. When the request comes, the master will pass it to a worker and then immediately accept the next request. This avoids repetitive work and naturally improves efficiency. In addition, when the worker is not enough, the master can start several workers in advance according to the configuration. Of course, when there are too many idle workers, some will also be stopped, which improves performance and saves resources. This is how Fastcgi manages processes.
As mentioned above, Fastcgi is only a solution or protocol, so php-fpm is the program that implements Fastcgi. That is to say, the process allocation and management described above are implemented by FPM. The official explanation of FPM is:Fastcgi Process Manager (Fastcgi Process Manager ).
PHP concurrent access Processing
PHP does not support multi-threaded operations at the code level. It cannot write multi-threaded code like Java or C. However, multithreading is not directly related to concurrency. multithreading only executes multiple thread tasks at the same time during code execution to improve the server CPU utilization and code efficiency. However, php supports multi-process execution. The FPM process management mechanism described above is multi-process and single-thread, which effectively improves the response efficiency of concurrent access.
- Simple web server + php-fpm Mode
1. When the client sends a request, the web serverA php-fpm Process(The fpm processes mentioned in the following sections are all worker processes enabled by fpm, and the working principles of fpm are not described here) to execute php code, the execution of php code isSingle thread.
2. When multiple clients send requests simultaneously (concurrently), the web server starts a separate process for each request through php-fpm to execute php code.
3. After the request is executed, the idle php-fpm process is destroyed and the memory is released.
4. however, the concurrency problem is that at a certain time, the number of php-fpm processes allowed by client requests reaches the maximum limit. At this time, new requests can only be processed by idle php-fpm processes.Multi-Process Synchronization Blocking ModeOf course, there is also a problem of memory usage caused by too many processes.