FastCGI
2010-09-27 13:10:02 阿炯

FastCGI是一个程序接口,它能加速公共网关接口(CGI),CGI是一种用最常见的方式使Web服务器调用应用程序的Web应用程序。按一个 FastCGI工具来看,用户要求进入一个网站并使用一个专门的应用软件的话,使用FastCGI能够快3到30倍。FastCGI是Web服务器的一种插件,为了获得良好的性能,它要求对现有服务器应用程序(比如Perl 、Tcl 脚本和C、C++程序)做细小的改动。



FastCGI is simple because it is actually CGI with only a few extensions.

基本上,FastCGI 是一个在单一步骤中管理多重CGI请求的程序,为每个请求减少了许多程序指令。没有FastCGI的话,每当用户请求某一服务时都会导致Web服务器打开一个新的能控制和执行这项服务的程序,然后关闭它。有了FastCGI的话,一个步骤的耗费会被所有当前正处理的请求所分担。与CGI不同,有了 FastCGI 的话,每个步骤是独立于Web服务器运行的,这样就提供了更多的安全。FastCGI 是独立代码的,它的版权属于Open Market公司,该公司提供FastCGI的免费使用并且将其作为一个公开标准。FastCGI提供了唯一一个可以跨平台和在任何Web服务器上使用的无知识产权的方法。

从技术角度看,fastcgi的优点还是很多的,作为一种替代cgi的技术标准,fastcgi有如下优点:(稳定、安全、高性能、方便扩展)
*从稳定性上看,fastcgi是以独立的进程池运行来cgi,单独一个进程死掉,系统可以很轻易的丢弃,然后重新分配新的进程来运行逻辑。

*从安全性上看,fastcgi和宿主的server完全独立,fastcgi怎么down也不会把server搞垮。

*从性能上看,fastcgi把动态逻辑的处理从server中分离出来,大负荷的IO处理还是留给宿主server, 这样宿主server可以一心一意作IO,对于一个普通的动态网页来说,逻辑处理可能只有一小部分,大量的图片等静态IO处理完全不需要逻辑程序的参与。

*从扩展性上讲,fastcgi是一个中立的技术标准,完全可以支持任何语言写的处理程序(perl、php、java、python...)

* Like CGI, FastCGI is also language-independent. For instance, FastCGI provides a way to improve the performance of the thousands of Perl applications that have been written for the Web.

* Like CGI, FastCGI runs applications in processes isolated from the core Web server, which provides greater security than APIs. (APIs link application code into the core Web server, which means that a bug in one API-based application can corrupt another application or the core server; a malicious API-based application can, for example, steal key security secrets from another application or the core server.)

* Although FastCGI cannot duplicate the universality of CGI overnight, the FastCGI developers are committed to propagating FastCGI as an open standard. To that end, free FastCGI application libraries (C/C++, Java, Perl, Tcl) and upgrade modules for popular free servers (Apache, ISS, Lighttpd) are available.

* Like CGI, FastCGI is not tied to the internal architecture of any Web server and is therefore stable even when server technology changes. An API reflects the internal architecture of a Web server, so when that architecture changes, so does the API.

Not only does FastCGI restore the strengths of CGI, it also adds two new benefits:

* Distributed computing: Companies can run their FastCGI application on a different machine from the one on which they run their Web server. Distributed computing is a proven technique for scaling, linking to existing corporate systems, improving system availability, and improving security via compartmentalization, such as firewalls.

* Multiple and extensible roles: CGI applications compute the response to an HTTP request. FastCGI applications can do that and more, such as perform modular authentication and authorization checks and translate data from one type to another. FastCGI is designed so that more roles can be introduced in the future.

原来很多人都用 Lighttpd 的 Spawn-fcgi 进行 FastCGI 模式下的管理工作,不过有不少缺点。而 PHP-fpm 的出现多少缓解了一些问题,但 PHP-fpm 有个缺点就是要重新编译,这对于一些已经运行的环境可能有不小的风险(refer)。

最新版本:2.4


官方主页:http://www.fastcgi.com/

该文章最后由 阿炯 于 2013-06-18 20:44:40 更新,目前是第 2 版。