For CGI fastcgi php-fpm php-cgi explanation, online quite a lot of, can Baidu view, below is my own understanding
Noun terms:
1、web服务器2、通信协议3、进程、主进程、子进程4、php解析器CGI:Common Gateway Interface 公共网关接口,web服务器和脚本语言通信的一个标准、接口、协议【协议】FastCGI:CGI协议的升级版【协议】PHP-CGI: 实现了CGI接口协议的PHP脚本解析器【程序】PHP-FPM: 管理和调度php-cgi进程,进而实现了FastCGI接口协议的程序【程序】
webserver只能处理静态文件,对于php这样的动态脚本无能为力,只能交给php自己来处理,于是有了下面这个流程:
但是上面架构有个性能问题,CGI对每个请求会parse一遍对应脚本的配置文件(如php.ini),加载配置和扩展,初始化执行环境,性能非常差,所有有了下面的流程:
So how does the program that implements the FASTCGI protocol, such as PHP-FPM, do? First, fastcgi initiates a master process, parses the configuration file, initializes the execution environment, and then starts multiple worker processes, the worker being php-cgi. When the request comes in, master passes it to a worker, and then immediately accepts the next request. This avoids duplication of labor, and efficiency is naturally high. And when the worker is not enough, master can be configured to pre-boot several workers, such as 20worker, of course, too many idle workers, will also stop some, so that improves performance, but also saves resources. This is FastCGI's management of the process.
Here are the configuration entries for the number of workers in the PHP-FPM configuration file:
; The maximum number of processes FPM will fork. This has been design to control; the global number of processes when using dynamic PM within a lot of pools.; Use it with caution.; Note: A value of 0 indicates no limit; Default Value: 0; process.max = 128
So the maximum number of worker processes is 128.
More explanations for fastcgi.
fastcgi是基于cgi架构的扩展,他的核心思想就是在web server和具体cgi程序之间建立一个智能的可持续的中间层,统管cgi程序的运行,这样web server只需要将请求提交给这个层,这个层再派生出几个可复用的cgi程序实例,然后再把请求分发给这些实例,这些实例是可控的,可持续,可复用的,因此一方面避免了进程反复fork,另一方面又可以通过中间层的控制和探测机制来监视这些实例的运行情况,根据不同的状况fork或者回收实例,达到灵活性和稳定性兼得的目的。
Reference documents
https://segmentfault.com/q/1010000000256516
http://blog.csdn.net/zhuanshenweiliu/article/details/46413241
The above describes the Nginx, CGI, FastCGI, php-cgi, PHP-FPM processing process, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.