FastCGI
This article includes a list of references, but its sources remain unclear because it has insufficient inline citations. (June 2010) (Learn how and when to remove this template message) |
FastCGI is a binary protocol for interfacing interactive programs with a web server. FastCGI is a variation on the earlier Common Gateway Interface (CGI); FastCGI's main aim is to reduce the overhead associated with interfacing the web server and CGI programs, allowing a server to handle more web page requests per same amount of time.
Contents
History[edit]
CGI is a protocol for interfacing external applications to web servers. CGI applications run in separate processes, which are created at the start of each request and torn down at the end. This "one new process per request" model makes CGI programs very simple to implement, but limits efficiency and scalability. At high loads, the operating system process creation and destruction overhead becomes significant. In addition, the CGI process model limits resource reuse techniques (such as reusing database connections, in-memory caching, etc.).
To address the scalability shortcomings of CGI, Open Market developed FastCGI and first introduced it in their webserver product in the mid-1990s. Open Market originally developed FastCGI in part as a competitive response to Netscape's proprietary, in-process API (NSAPI) for developing Web applications.
Although initially developed by Open Market, FastCGI was implemented by a number of other webserver makers. The FastCGI approach, however, competed against other techniques which also aimed to speed and simplify server-subprogram communications. Apache modules such as mod_perl and mod_php appeared around the same time, and they also quickly gained popularity. Today, all of these various approaches (including CGI) remain in common use.
Implementation details[edit]
Instead of creating a new process for each request, FastCGI uses persistent processes to handle a series of requests. These processes are owned by the FastCGI server, not the web server. [1]
To service an incoming request, the web server sends environment information and the page request itself to a FastCGI process over either a Unix domain socket, a named pipe or a TCP connection. Responses are returned from the process to the web server over the same connection, and the web server subsequently delivers that response to the end-user. The connection may be closed at the end of a response, but both the web server and the FastCGI service processes persist.[2]
Each individual FastCGI process can handle many requests over its lifetime, thereby avoiding the overhead of per-request process creation and termination. Processing of multiple requests simultaneously can be achieved in several ways: by using a single connection with internal multiplexing (i.e. multiple requests over a single connection); by using multiple connections; or by a combination of these techniques. Multiple FastCGI servers can be configured, increasing stability and scalability.
Web site administrators and programmers can find that the separation of web applications from the web server in FastCGI has many advantages over embedded interpreters (mod_perl, mod_php, etc.). This separation allows server and application processes to be restarted independently – an important consideration for busy web sites. It also enables the implementation of per-application / hosting service security policies, which is an important requirement for ISPs and web hosting companies.[3] Different types of incoming requests can be distributed to specific FastCGI servers which have been equipped to handle those particular types of requests efficiently.
Web Servers that implement FastCGI[edit]
- Note: unless stated, completeness of FastCGI implementation is unknown
- Apache HTTP Server (partial)
- Implemented by mod_fcgid. This module used to be third-party, but was granted to the ASF as an Apache HTTP Server subproject in 2009, shepherded by Chris Darroch.[4] It only supports UNIX sockets, no TCP sockets.[5]
- A third-party module mod_fastcgi is also being used. For a while, this module no longer compiled properly under Apache 2.4.x,[6] although that problem has been solved with a fork of the original project.[7]
- Multiplexing of requests through a single connection is prohibited by Apache 1.x design,[8] so this isn't supported
- In Apache 2.4, mod_proxy_fcgi was added, supporting TCP FastCGI servers.
- Caddy [9]
- Cherokee[10]
- Hiawatha[11]
- Loadbalancing FastCGI support
- Supports chrooted FastCGI servers
- Jetty[12]
- Kerio WebSTAR
- Lighttpd[13]
- LiteSpeed Web Server
- Microsoft IIS[14]
- Nginx
- NaviServer
- Oracle iPlanet Web Server
- OpenBSD's httpd(8)[15]
- Open Market Web Server
- Resin Application Server
- Roxen Web Server
- ShimmerCat web server.[16]
- Zeus Web Server
Language bindings for the FastCGI API[edit]
FastCGI can be implemented in any language that supports network sockets. (Since "FastCGI is a protocol, not an implementation," it is not tightly bound to any language at all.) APIs exist[17] for:
- Ada[18]
- Borland Delphi/Lazarus FreePascal[19]
- C / C++
- Chicken Scheme
- Common Lisp[20]
- D programming language
- Eiffel[21]
- Erlang (programming language)
- GnuCOBOL
- Go
- Guile Scheme
- Haskell
- HP BASIC for OpenVMS
- Java[22][12]
- Lua
- node.js[23]
- OCaml
- Perl[24]
- PHP (via php-fpm[25], or HipHop for PHP[26])
- Python
- REALbasic (REAL Studio)[27]
- Ruby
- Rust[28]
- SmallEiffel
- Smalltalk: FasTalk and Dolphin Smalltalk
- Tcl
- WebDNA
- Vala (via C bindings)
Recent frameworks such as Ruby on Rails, Catalyst, Django, Kepler and Plack allow use with either the embedded interpreters (mod_ruby, mod_perl, mod_python or mod_lua, for example), or FastCGI.
References[edit]
- ^ "FastCGI Specification". Open Market, Inc. 1996. Archived from the original on 19 January 2016.
- ^ "FastCGI:A High-Performance Web Server Interface". Open Market, Inc. 1996. Archived from the original on 1 October 2010.
- ^ Paul Heinlein (1 November 1998). "FastCGI: Persistent Applications for Your Web Server". Linux Journal. Retrieved 4 October 2010.
- ^ FastCGI apache module mod_fcgid
- ^ Debian bug #450748: Please add support for TCP/IP FastCGI servers
- ^ Issues with Apache 2.4 and PHP-FPM
- ^ libapache-mod-fastcgi on Github
- ^ FastCGI – The Forgotten Treasure/ Section 2.3.
- ^ Caddy User Guide – FastCGI
- ^ FastCGI for Cherokee
- ^ FastCGI HOWTO for Hiawatha
- ^ a b FastCGI Support in Jetty
- ^ FastCGI for Lighttpd
- ^ "FastCGI Extension for IIS6.0 - RTM". FastCGI for IIS. Microsoft. 2008-02-28. Retrieved 2008-02-29.
- ^ OpenBSD's httpd(8) initial commit
- ^ [1]
- ^ Application Libraries / Development Kits
- ^ Matreshka
- ^ ExtPascal
- ^ How to use FastCGI from Common Lisp
- ^ Goanna Eiffel
- ^ jFastCGI, a Java Servlet implementing FastCGI protocol
- ^ node-fastcgi npm package
- ^ There are a number of FastCGI modules for Perl: FCGI (a compiled module written in C), FCGI::Async (for asynchronous FastCGI applications), AnyEvent::FCGI (for AnyEvent-based applications), FCGI::EV (for EV-based applications), CGI::Fast (Perl CGI-like interface for FastCGI), FCGI::Client (a FastCGI client library), and Net::FastCGI (constants and functions to build and parse FastCGI messages).
- ^ [2]
- ^ FasterCGI with HHVM
- ^ REAL Studio Web Edition, builds web apps called via FastCGI Archived 2011-02-08 at the Wayback Machine
- ^ [3]