Heim  >  Artikel  >  Backend-Entwicklung  >  PHP: CGI,FASTCGI,php-fpm,mod_php,mod_cgi,mod_fcgid 解释

PHP: CGI,FASTCGI,php-fpm,mod_php,mod_cgi,mod_fcgid 解释

WBOY
WBOYOriginal
2016-06-23 13:44:47953Durchsuche

有些常用概念不注意的时候会有所混淆,简略罗列下。


1. CGI是通用网关接口,HTTP服务器使用这样的接口程序来和其他应用(比如PHP的解释器程序)通讯,由于CGI采用fork and execution方式,

每次请求都需要新建立CGI程序来进行处理,这样导致性能低下。


2. FASTCGI是常驻内存的CGI,实际上是对CGI程序的进程管理,通过master进程接受请求,分发给worker进程,并可以prefork worker进程,减少CGI进程创建、初始化和销毁的开销,从而提高性能。


3. mod_php是apache的内置php解释模块,使用prefork方式,不需要额外的进程来做通讯和应用解释,显然mod_php比mod_cgi这样方式性能要好得多,但缺点是把应用和HTTP服务器绑定在了一起,另外每个Apache进程都需要加载mod_php而不论这个请求是处理静态内容还是动态内容,这样导致浪费内存,效率下降,此外php.ini文件的变更需要重新启动apache服务器才能生效,这使得无法进行平滑配置变更。


4. php-fpm是常和nginx搭配使用的程序,php-fpm实际上就是对FASTCGI协议的一个加强实现,已经被纳入PHP内核,可以通过--enable-fpm编译选项来启用,php-fpm支持配置的平滑变更(通过fork新的worker进程),性能好,内存使用效率高,这也是为什么nginx+php-fpm的配置组合会替代apache+mod_cgi以及apache+mod_php的重要原因。


5. mod_fcgid是apache的fastcgi实现,性能也很好,在apache的2.4以后的版本中得到支持。


参考阅读:

http://httpd.apache.org/mod_fcgid/

http://www.openlogic.com/wazi/bid/209956/mod_php-vs-FastCGI-vs-PHP-FPM-for-Web-Server-Scripting

http://www.eschrade.com/page/why-is-fastcgi-w-nginx-so-much-faster-than-apache-w-mod_php/

http://serverfault.com/questions/6733/php-what-are-the-advantages-of-fastcgi-over-mod-php

by cstopery

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:php学习类的使用Nächster Artikel:提示它的原因是什么