m5k1umn 发表于 2024-10-4 19:35:55

php的几种运行模式CLI、CGI、FastCGI、mod_php


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">1、CLI:</span>(<span style="color: black;">command-line interface</span>)<span style="color: black;">命令行接口</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">能够</span>在<span style="color: black;">掌控</span>台<span style="color: black;">或</span>是shell中键入命令。如:</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">php index.php</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">2、CGI :(Common Gateway Interface)公共网关接口</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">CGI<span style="color: black;">实质</span>上是一种程序之间的交互协议,<span style="color: black;">一般</span><span style="color: black;">做为</span>HTTP Server和“程序”进行“<span style="color: black;">交流</span>”的一种工具。<span style="color: black;">这儿</span>的“程序”即实现了CGI协议的程序,<span style="color: black;">咱们</span><span style="color: black;">能够</span><span style="color: black;">叫作</span>之为CGI程序,CGI程序的实现语言并<span style="color: black;">无</span><span style="color: black;">需求</span>。例如PHP-CGI<span style="color: black;">便是</span>实现了CGI协议的CGI程序,而HTTP Server本身<span style="color: black;">亦</span>要实现CGI协议<span style="color: black;">才可</span>和PHP-CGI交互。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">经过</span>CGI协议,<span style="color: black;">保准</span>了HTTP Server传递过来的数据是标准格式的,以方便CGI程序的编写者。服务器要支持CGI就要<span style="color: black;">供给</span>CGI中<span style="color: black;">需求</span>的环境变量,<span style="color: black;">或</span>还有别的。该协议<span style="color: black;">需求</span>HTTP Server把HTTP Request的Header设置成CGI程序的环境变量,HTTP Request的正文设置成CGI程序的标准输入,而CGI程序的标准输出<span style="color: black;">便是</span>HTTP Response,<span style="color: black;">包含</span>Header和正文。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">再进一步<span style="color: black;">详细</span>举例来讲的话,php以CGI方式运行时,web server(<span style="color: black;">例如</span>说nginx)<span style="color: black;">按照</span>配置文件<span style="color: black;">晓得</span>这个不是静态文件,需要去找PHP解析器来处理,<span style="color: black;">那样</span>他会把这个请求简单处理后交给PHP-CGI。Nginx会传<span style="color: black;">那些</span>数据给PHP-CGI呢?url要有吧,查询字符串<span style="color: black;">亦</span>得有吧,POST数据<span style="color: black;">亦</span>要有,HTTP header<span style="color: black;">不可</span>少吧,好的,CGI协议<span style="color: black;">便是</span>规定要传<span style="color: black;">那些</span>数据、以什么样的格式传递给后方处理这个请求的协议。将用户请求以<span style="color: black;">信息</span>的方式转交给PHP-CGI独立进程。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">实质</span>上上面这个流程<span style="color: black;">亦</span>说明了一个问题<span style="color: black;">便是</span>PHP与web服务之间并不是从属关系。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">那样</span>,CLI和CGI有<span style="color: black;">那些</span><span style="color: black;">明显</span>区别呢?</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">(1)CLI与 CGI SAPI <span style="color: black;">区别</span>,CLI其输出<span style="color: black;">无</span>任何头信息。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">尽管 CGI SAPI <span style="color: black;">供给</span>了取消 HTTP 头信息的<span style="color: black;">办法</span>,但在 CLI SAPI 中并不存在类似的<span style="color: black;">办法</span>以开启 HTTP 头信息的输出。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">(2)CLI 默认以安静模式<span style="color: black;">起始</span>,但为了<span style="color: black;">保准</span>兼容性,-q 和 --no-header 参数为了向后兼容仍然<span style="color: black;">保存</span>,使得<span style="color: black;">能够</span><span style="color: black;">运用</span>旧的 CGI 脚本。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">(3)CLI在运行时,不会把工作目录改为脚本的当前目录(<span style="color: black;">能够</span><span style="color: black;">运用</span>-C和--no-chdir 参数来兼容CGI模式)。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">(4)CLI出错时输出纯文本的错误信息(非 HTML 格式)。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">3、FastCGI:(Fast Common Gateway Interface)快速公共网关接口</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">顾名思义,FastCGI是CGI的升级版本,运行速度更快。传统的CGI程序有<span style="color: black;">非常多</span>缺点,<span style="color: black;">例如</span>每接收一个请求就要fork一个新的进程去处理,每次只能接收一个请求作出一个响应,请求结束后该进程就会结束。而FastCGI程序会事先<span style="color: black;">起步</span>起来,<span style="color: black;">做为</span>一个cgi程序的管理服务器存在,预先<span style="color: black;">起步</span>一系列的子进程来等待处理,<span style="color: black;">而后</span>等待web服务器发过来的请求,一旦接受到请求就交由子进程处理,<span style="color: black;">这般</span><span style="color: black;">因为</span>不需要在接受到请求后<span style="color: black;">起步</span>cgi程序,<span style="color: black;">因此</span>会快<span style="color: black;">非常多</span>。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">FastCGI<span style="color: black;">运用</span>进程/线程池来处理一连串的请求。这些进程/线程由FastCGI服务器管理,而不是Web服务器。当进来一个请求时,Web服务器把环境变量和这个页面请求<span style="color: black;">经过</span>一个</span><strong style="color: blue;"><span style="color: black;">Socket长连接</span></strong><span style="color: black;">传递给FastCGI进程。FastCGI进程像是一个常驻型的CGI进程,它<span style="color: black;">能够</span><span style="color: black;">始终</span>执行,在请求到达时不会花费时间去fork一个进程来处理(这是CGI最为人诟病的fork-and-execute模式)。正是<span style="color: black;">由于</span>它只是一个通信协议,它还支持分布式的运算,即FastCGI程序<span style="color: black;">能够</span>在网站服务器以外的主机上执行并且接受来自其他网站服务器的请求。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">FastCGI<span style="color: black;">全部</span></span><strong style="color: blue;"><span style="color: black;">流程</span></strong><span style="color: black;">:</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">(1)Web server<span style="color: black;">起步</span>时载入FastCGI进程管理器</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">(2)FastCGI<span style="color: black;">自己</span>初始化,<span style="color: black;">起步</span>多个CGI解释器进程(可见多个php-cgi)并等待来自Web server的请求</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">(3)当请求Web server时,Web server<span style="color: black;">经过</span>socket请求FastCGI进程管理器,FastCGI进程管理器<span style="color: black;">选取</span>并连接到一个PHP-CGI,Web server将CGI环境变量和标准输入发送到FastCGI子进程PHP-CGI</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">(4)FastCGI子进程处理请求完成后将标准输出和错误从同一连接返回给Web server,当FastCGI子进程结束后请求便结束。FastCGI子进程接着等待处理来自FastCGI进程管理器的下一个连接。(在CGI模式中,php-cgi<span style="color: black;">这里</span>便退出了)。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">4、PHP-FPM:(PHP Fast CGI Process Manager)PHP-fastcgi进程管理器</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">PHP-FPM是一个实现了Fastcgi协议的程序,被PHP官方收了。<span style="color: black;">亦</span><span style="color: black;">能够</span>说php-fpm是实现了fastcgi协议的php-cgi进程的管理器,用来管理fastcgi进程的。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">经过</span>上面<span style="color: black;">咱们</span><span style="color: black;">晓得</span>,php-cgi只是一个CGI程序,他自己本身只能解析请求,返回结果,不会进程管理。<span style="color: black;">因此</span>就<span style="color: black;">显现</span>了<span style="color: black;">有些</span>能够调度php-cgi进程的程序,<span style="color: black;">例如</span>说由lighthttpd分离出来的spawn-fcgi。<span style="color: black;">因此</span>PHP-FPM<span style="color: black;">亦</span>是这么个东东,在<span style="color: black;">长期</span>的发展后,<span style="color: black;">逐步</span>得到了<span style="color: black;">大众</span>的认可(要<span style="color: black;">晓得</span>,前几年<span style="color: black;">大众</span>可是抱怨PHP-FPM稳定性太差的),<span style="color: black;">亦</span>越来越流行。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">5、mod_php:即apache的php模块</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">Mod_php模式将PHP做为web-server的子进程<span style="color: black;">掌控</span>,两者之间有从属关系.最<span style="color: black;">显著</span>的例子<span style="color: black;">便是</span>在CGI模式下,<span style="color: black;">倘若</span>修改了PHP.INI的配置文件,<span style="color: black;">不消</span>重启web服务便可生效,而模块模式下则需要重启web服务。以mod_php模式运行PHP,<span style="color: black;">寓意</span>着php是<span style="color: black;">做为</span>apache的一个模块来<span style="color: black;">起步</span>的,<span style="color: black;">因此呢</span><span style="color: black;">仅有</span>在apache<span style="color: black;">起步</span>的时候会读取php.ini配置文件并加载扩展模块,在apache运行<span style="color: black;">时期</span>是不会再去读取和加载扩展模块的</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">(1)Apache的工作模式</span></strong><strong style="color: blue;"><span style="color: black;">prefork的工作原理、</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">一个单独的<span style="color: black;">掌控</span>进程(父进程)负责产生子进程,这些子进程用于监听请求并作出应答。Apache总是试图保持<span style="color: black;">有些</span>备用的 (spare)或是空闲的子进程用于迎接即将到来的请求。<span style="color: black;">这般</span>客户端就无需在得到服务前等候子进程的产生。在Unix系统中,父进程<span style="color: black;">一般</span>以root身份运行以便邦定80端口,而 Apache产生的子进程<span style="color: black;">一般</span>以一个低特权的用户运行。User和Group指令用于配置子进程的低特权用户。运行子进程的用户必须要对他所服务的内容有读取的权限,<span style="color: black;">然则</span>对服务内容之外的其他资源必须<span style="color: black;">持有</span>尽可能少的权限。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">(2)worker的工作原理</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">每一个</span>进程能够<span style="color: black;">持有</span>的线程数量是固定的。服务器会<span style="color: black;">按照</span>负载<span style="color: black;">状况</span><span style="color: black;">增多</span>或减少进程数量。一个单独的<span style="color: black;">掌控</span>进程(父进程)负责子进程的<span style="color: black;">创立</span>。<span style="color: black;">每一个</span>子进程能够<span style="color: black;">创立</span>ThreadsPerChild数量的服务线程和一个监听线程,该监听线程监听接入请求并将其传递给服务线程处理和应答。Apache总是试图维持一个备用(spare)或是空闲的服务线程池。<span style="color: black;">这般</span>,客户端无须等待新线程或新进程的<span style="color: black;">创立</span><span style="color: black;">就可</span>得到处理。在Unix中,为了能够绑定80端口,父进程<span style="color: black;">通常</span>都是以root身份<span style="color: black;">起步</span>,随后,Apache以较低权限的用户<span style="color: black;">创立</span>子进程和线程。User和Group指令用于配置Apache子进程的权限。虽然子进程必须对其<span style="color: black;">供给</span>的内容<span style="color: black;">持有</span>读权限,但应该尽可能给予他较少的特权。<span style="color: black;">另一</span>,除非<span style="color: black;">运用</span>了suexec ,否则,这些指令配置的权限将被CGI脚本所继承</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">个人理解:这种模式把php嵌入到apache中,相当于给apache加入<span style="color: black;">认识</span>析php文件的功能。</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">6、基于fast-cgi协议模式的nginx和php-fpm交互细节</strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">Nginx与PHP-fpm之间<span style="color: black;">经过</span>socket进行通讯,<span style="color: black;">重点</span>有两种通信方式unix socket和tcp socket</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">(1)nginx配置比较</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">unix socket需要在nginx配置文件中填写php-fpm运行的pid文件(即sock文件)<span style="color: black;">位置</span>。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">location ~ \.php$ {</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">include fastcgi_params;</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;;</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">fastcgi_pass unix:/var/run/php5-fpm.sock;</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">fastcgi_index index.php;</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">}</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">tcp socket需要在nginx配置文件中填写php-fpm运行的ip<span style="color: black;">位置</span>和端口号。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">location ~ \.php$ {</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">include fastcgi_params;</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;;</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">fastcgi_pass 127.0.0.1:9000;</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">fastcgi_index index.php;</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">}</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">(2)特点比较</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">从上面的<span style="color: black;">照片</span><span style="color: black;">能够</span>看,unix socket减少了不必要的tcp开销,而tcp需要经过loopback,还要申请临时端口和tcp<span style="color: black;">关联</span>资源。<span style="color: black;">然则</span>,unix socket高并发时候不稳定,连接数爆发时,会产生<span style="color: black;">海量</span>的长时缓存,在<span style="color: black;">无</span>面向连接协议的支撑下,大数据包可能会直接出错不返回<span style="color: black;">反常</span>。tcp<span style="color: black;">这般</span>的面向连接的协议,多少<span style="color: black;">能够</span><span style="color: black;">保准</span>通信的正确性和完整性。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">选取</span><span style="color: black;">意见</span>:<span style="color: black;">倘若</span>是在同一台服务器上运行的nginx和php-fpm,并发量不超过1000,<span style="color: black;">选取</span>unix socket,<span style="color: black;">由于</span>是本地,<span style="color: black;">能够</span>避免<span style="color: black;">有些</span><span style="color: black;">检测</span>操作(路由等),<span style="color: black;">因此呢</span>更快,更轻。 <span style="color: black;">倘若</span>面临高并发业务,我会<span style="color: black;">选取</span><span style="color: black;">运用</span>更<span style="color: black;">靠谱</span>的tcp socket,以负载<span style="color: black;">平衡</span>、内核优化等运维手段维持效率。</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">(3)nginx和php<span style="color: black;">协同</span>处理请求的通用流程:</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">1. nginx.conf配置webserver参数, 请求PHP类应用可配置fastcgi_pass,指明监听端口或socket<span style="color: black;">位置</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">2. php-fpm.conf中listen<span style="color: black;">位置</span>与nginx.conf fastcgi_pass字段配置一致(sock文件或是端口),<span style="color: black;">显示</span>php-fpm worker进程监听<span style="color: black;">目的</span></span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">3. <span style="color: black;">起步</span>后,请求先到达nginx server端口,分发到对应位置,若配置了fastcgi-pass,则被转到对应端口或socket,php-fpm master进程监听到,再创建fork worker进程<span style="color: black;">实质</span>运行,运行结束返回给nginx。即如下所示:</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">www.example.com =》</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">Nginx =》</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">路由到www.example.com/index.php =》</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">加载nginx的fast-cgi模块 =》</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">fast-cgi监听127.0.0.1:9000<span style="color: black;">位置</span>=》</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">www.example.com/index.php请求到达127.0.0.1:9000 =》</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">php-fpm 监听127.0.0.1:9000 =》</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">php-fpm 接收到请求,启用worker进程处理请求 =》</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">php-fpm 处理完请求,返回给nginx =》</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">nginx将结果<span style="color: black;">经过</span>http返回给浏览器</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">因此</span>综上所述,Nginx和phpcgi都是实现了cgi协议的cgi程序,cgi协议规定了交互(输入和输出)的数据格式和方式,这个方式<span style="color: black;">便是</span>socket。</span></strong></span></p>




nqkk58 发表于 2024-10-8 22:12:48

楼主继续加油啊!外链论坛加油!

b1gc8v 发表于 2024-10-15 17:59:54

我们有着相似的经历,你的感受我深有体会。

j8typz 发表于 前天 05:39

你的见解真是独到,让我受益匪浅。
页: [1]
查看完整版本: php的几种运行模式CLI、CGI、FastCGI、mod_php