FastCGI
{{Short description|Binary communications protocol}}
{{More footnotes|date=June 2010}}
FastCGI is a binary protocol for interfacing interactive programs with a web server. It is a variation on the earlier Common Gateway Interface (CGI). FastCGI's main aim is to reduce the overhead related to interfacing between web server and CGI programs, allowing a server to handle more web page requests per unit of time.
History
Common Gateway Interface (CGI) is an interface specification allowing external applications to interact with 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 overhead for process creation and destruction becomes significant. Also, the CGI process model limits resource reuse methods, 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 application programming interfaces (APIs) (Netscape Server Application Programming Interface (NSAPI)) for developing Web applications.
While developed first by Open Market, FastCGI was then implemented by several other webserver makers. However, its approach competed against other methods to speed and simplify server-subprogram communication. Apache HTTP Server modules such as mod_perl and mod_php appeared around the same time, and gained popularity quickly. {{As of|2020}}, all of these various methods, including CGI, remain in common use.
Implementation details
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.{{cite web |url-status=dead |archive-url=https://web.archive.org/web/20160119141816/http://www.fastcgi.com/drupal/node/6?q=node%2F22 |archive-date=19 January 2016 |url=http://www.fastcgi.com/drupal/node/6?q=node/22 |title=FastCGI Specification |year=1996 |website=Open Market, Inc. }}
To service an incoming request, the web server sends environment variable information and the page request to a FastCGI process over either a Unix domain socket, a named pipe, or a Transmission Control Protocol (TCP) connection. Responses are returned from the process to the web server over the same connection, and the web server then delivers that response to the end user. The connection may be closed at the end of a response, but both web server and FastCGI service processes persist.{{cite web |title=FastCGI:A High-Performance Web Server Interface |year=1996 |website=Open Market, Inc |url=http://www.fastcgi.com:80/drupal/node/6?q=node/15 |url-status=dead |archive-url=https://web.archive.org/web/20101001152455/http://www.fastcgi.com/drupal/node/6?q=node%2F15 |archive-date=1 October 2010 }}
Each individual FastCGI process can handle many requests over its lifetime, thereby avoiding the overhead of per-request process creation and termination. Processing multiple requests concurrently can be done in several ways: by using one connection with internal multiplexing (i.e., multiple requests over one connection); by using multiple connections; or by a mix of these methods. Multiple FastCGI servers can be configured, increasing stability and scalability.
Web site administrators and programmers can find that separating 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.{{cite web |url=http://www.linuxjournal.com/article/2607 |title=FastCGI: Persistent Applications for Your Web Server |last=Heinlein |first=Paul |date=1 November 1998 |website=Linux Journal |access-date=4 October 2010}} Different types of incoming requests can be distributed to specific FastCGI servers which have been equipped to handle those types of requests efficiently.
Web servers that implement FastCGI
{{See also|Comparison of web server software#Features}}
:Note: unless stated, completeness of FastCGI implementation is unknown
- Apache HTTP Server (partial)
- Implemented by {{mono|[http://httpd.apache.org/mod_fcgid/ mod_fcgid]}}. This module used to be third-party, but was granted to The Apache Software Foundation (ASF) as an Apache Server subproject in 2009, shepherded by Chris Darroch.[http://httpd.apache.org/mod_fcgid/ FastCGI apache module mod_fcgid] It only supports Unix domain sockets, no TCP sockets.[http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=450748 Debian bug #450748: Please add support for TCP/IP FastCGI servers]
- A third-party module {{mono|mod_fastcgi}} is also being used. For a while, this module no longer compiled properly under Apache 2.4.x,[https://web.archive.org/web/20120327033316/http://danielhe.com/2012/03/issues-with-apache-2-4-and-php-fpm/ Issues with Apache 2.4 and PHP-FPM] although that problem has been solved with a fork of the original project.[https://github.com/ByteInternet/libapache-mod-fastcgi/ libapache-mod-fastcgi on Github]
- Multiplexing of requests through one connection is prohibited by Apache 1.x design,{{Cite web |url=http://cryp.to/publications/fastcgi/#AEN147 |title=FastCGI – The Forgotten Treasure/ Section 2.3. |access-date=2006-02-21 |archive-url=https://web.archive.org/web/20100208215702/http://cryp.to/publications/fastcgi/#AEN147 |archive-date=2010-02-08 |url-status=dead }} so this isn't supported
- In Apache 2.4, {{mono|[http://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html mod_proxy_fcgi]}} was added, supporting TCP FastCGI servers.
- Caddy[https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#the-fastcgi-transport The fastcgi transport — reverse_proxy (Caddyfile directive) — Caddy Documentation]
- Cherokee[http://www.cherokee-project.com/doc/modules_handlers_fcgi.html FastCGI for Cherokee]
- Hiawatha[http://www.hiawatha-webserver.org/howto/cgi_and_fastcgi FastCGI howto for Hiawatha]
- Loadbalancing FastCGI support
- Supports chrooted FastCGI servers
- Jetty{{Cite web |url=http://www.eclipse.org/jetty/documentation/current/fastcgi.html |title=FastCGI Support in Jetty |access-date=2017-03-23 |archive-date=2020-03-24 |archive-url=https://web.archive.org/web/20200324073821/http://www.eclipse.org/jetty/documentation/current/fastcgi.html |url-status=dead }}
- Kerio WebSTAR
- Lighttpd[http://trac.lighttpd.net/trac/wiki/Docs:ModFastCGI FastCGI for Lighttpd]
- LiteSpeed Web Server
- Microsoft IIS{{cite web
|url=http://www.iis.net/fastcgi
|title=FastCGI Extension for IIS6.0 – RTM
|work=FastCGI for IIS
|access-date=2008-02-29
|date=2008-02-28
|publisher=Microsoft
}}
- Nginx{{cite web |title=FastCGI Nginx module ngx_http_fastcgi_module |url=https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html |website=nginx.org |publisher=NGINX, Inc. |access-date=20 June 2021}}
- NaviServer
- Oracle iPlanet Web Server
- OpenBSD's {{mono|[http://man.openbsd.org/OpenBSD-current/man8/httpd.8 httpd(8)]}}[http://marc.info/?l=openbsd-cvs&m=140520832128782&w=2 OpenBSD's httpd(8) initial commit]
- Open Market web server
- Resin web and application server
- Roxen web server
- ShimmerCat web server{{Cite web |url=https://www.shimmercat.com/en/docs/1.5/featureset/#for-communications-with-backend-applications |title=Technical sheet |access-date=2016-09-19 |archive-url=https://web.archive.org/web/20180121071419/https://www.shimmercat.com/en/docs/1.5/featureset/#for-communications-with-backend-applications |archive-date=2018-01-21 |url-status=dead }}
- Zeus Web Server
Language bindings for its API
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 one language. Application programming interfaces (APIs) exist for:[https://fastcgi-archives.github.io Application Libraries, Development Kits]
{{columns-list|colwidth=20em|
- Ada{{Cite web |url=http://forge.ada-ru.org/matreshka |title=Matreshka |access-date=2011-10-06 |archive-date=2018-01-20 |archive-url=https://web.archive.org/web/20180120182200/http://forge.ada-ru.org/matreshka |url-status=dead }}
- Delphi, Lazarus Free Pascal[https://github.com/farshadmohajeri/extpascal ExtPascal]
- C, C++
- Chicken Scheme
- Common Lisp[http://cliki.net/fastcgi How to use FastCGI from Common Lisp]
- D
- Eiffel[https://svn.eiffel.com/goanna/trunk/goanna/ Goanna Eiffel]
- Erlang
- GnuCOBOL
- Go
- Guile Scheme
- Haskell
- VSI BASIC for OpenVMS
- Java[http://jfastcgi.org/ jFastCGI, a Java Servlet implementing FastCGI protocol]
- Lua
- node.js[https://www.npmjs.org/package/node-fastcgi node-fastcgi npm package]
- OCaml
- Perl
There are several FastCGI modules for Perl:
[http://metacpan.org/module/FCGI FCGI] (a compiled module written in C),
[http://metacpan.org/module/FCGI::Async FCGI::Async] (for asynchronous FastCGI applications),
[http://metacpan.org/module/AnyEvent::FCGI AnyEvent::FCGI]
(for [http://metacpan.org/module/AnyEvent AnyEvent]-based applications),
[http://metacpan.org/module/FCGI::EV FCGI::EV]
(for [http://metacpan.org/module/EV EV]-based applications),
[http://metacpan.org/module/CGI::Fast CGI::Fast]
(Perl [http://metacpan.org/module/CGI CGI]-like interface for FastCGI),
[http://metacpan.org/module/FCGI::Client FCGI::Client] (a FastCGI client library),
and [http://metacpan.org/module/Net::FastCGI Net::FastCGI]
(constants and functions to build and parse FastCGI messages).
- PHP (via php-fpm,{{cite web | url=http://php.net/manual/en/install.fpm.php | title=PHP: FastCGI Process Manager (FPM) - Manual }} or HipHop for PHP[http://www.hhvm.com/blog/1817/fastercgi-with-hhvm FasterCGI with HHVM])
- Python
- Ruby
- RustSeveral Rust crates exist: A listener implementation is [https://crates.io/crates/fastcgi fastcgi], and [https://crates.io/crates/fastcgi-client fastcgi-client] is a client implementation.
- SmallEiffel
- Smalltalk: FasTalk and Dolphin Smalltalk
- Tcl
- Vala (via C bindings)
- Xojo (formerly Realbasic, REAL Studio)[http://www.realsoftware.com/web/ REAL Studio Web Edition, builds web apps called via FastCGI] {{webarchive|url=https://web.archive.org/web/20110208052013/http://realsoftware.com/web/ |date=2011-02-08}}
}}
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
{{Reflist}}
External links
- {{cite web
|title = FastCGI.com Archives
|url = https://fastcgi-archives.github.io/
|access-date = 2022-05-01
}} — fork/mirror of down FastCGI website
- {{cite web
|title = FastCGI Specification
|author = Mark R. Brown
|publisher = Open Market, Inc.
|version = Document version 1.0
|date = 29 April 1996
|url = https://fastcgi-archives.github.io/FastCGI_Specification.html
|access-date = 2022-05-01
}}
- {{cite web
|title = FastCGI
|archive-url = https://web.archive.org/web/20160320065247/http://www.fastcgi.com/drupal/
|archive-date = 2016-03-20
|url = http://www.fastcgi.com/drupal/
|url-status = dead
}} — Old FastCGI home page, as it appeared when working
- Implementations
- {{cite web
|title = mod_fcgid - FastCGI interface module for Apache 2 - The Apache HTTP Server Project
|publisher = Apache Software Foundation
|date = 2013-10-08
|version = Version 2.3.9
|url = https://httpd.apache.org/mod_fcgid/
|access-date = 2022-05-01
}} — Implementation for Apache httpd
- {{cite web
|title = FastCGI
|work = Internet Information Server documentation
|publisher = Microsoft
|date = 2022-04-06
|url = https://docs.microsoft.com/en-us/iis/configuration/system.webserver/fastcgi/
|access-date = 2022-05-01
|url-status = live
|archive-url = https://web.archive.org/web/20220127050841/https://docs.microsoft.com/en-us/iis/configuration/system.webserver/fastcgi/
|archive-date = 2022-01-27
}} — Implementation for Microsoft IIS
- {{cite web
|title = Proxy FastCGI Scheme Apache Module
|publisher = ZenProjects
|date = 2017-10-09
|url = https://zenprojects.github.io/Apache-Proxy-FastCGI-Module/
|access-date = 2022-05-01
}} — Experimental implementation for Apache 2.x mod_proxy
{{Web interfaces}}
{{DEFAULTSORT:Fastcgi}}