FastCGI

Last updated

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.

Contents

History

Common Gateway Interface (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 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. [1]

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. [2]

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. [3] 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

Note: unless stated, completeness of FastCGI implementation is unknown

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: [18]

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.

Related Research Articles

<span class="mw-page-title-main">Apache HTTP Server</span> Open-source web server software

The Apache HTTP Server is a free and open-source cross-platform web server software, released under the terms of Apache License 2.0. It is developed and maintained by a community of developers under the auspices of the Apache Software Foundation.

In computing, Common Gateway Interface (CGI) is an interface specification that enables web servers to execute an external program to process HTTP or HTTPS user requests.

<span class="mw-page-title-main">Web server</span> Computer software that distributes web pages

A web server is computer software and underlying hardware that accepts requests via HTTP or its secure variant HTTPS. A user agent, commonly a web browser or web crawler, initiates communication by making a request for a web page or other resource using HTTP, and the server responds with the content of that resource or an error message. A web server can also accept and store resources sent from the user agent if configured to do so.

<span class="mw-page-title-main">Proxy server</span> Computer server that makes and receives requests on behalf of a user

In computer networking, a proxy server is a server application that acts as an intermediary between a client requesting a resource and the server providing that resource. It improves privacy, security, and performance in the process.

mod_perl is an optional module for the Apache HTTP server. It embeds a Perl interpreter into the Apache server. In addition to allowing Apache modules to be written in the Perl programming language, it allows the Apache web server to be dynamically configured by Perl programs. However, its most common use is so that dynamic content produced by Perl scripts can be served in response to incoming requests, without the significant overhead of re-launching the Perl interpreter for each request.

lighttpd

lighttpd is an open-source web server optimized for speed-critical environments while remaining standards-compliant, secure and flexible. It was originally written by Jan Kneschke as a proof-of-concept of the c10k problem – how to handle 10,000 connections in parallel on one server, but has gained worldwide popularity. Its name is a portmanteau of "light" and "httpd".

The Web Server Gateway Interface is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, version 1.0.1, is specified in Python Enhancement Proposal (PEP) 3333.

The Simple Common Gateway Interface (SCGI) is a protocol for applications to interface with HTTP servers, as an alternative to the CGI protocol. It is similar to FastCGI but is designed to be easier to parse. Unlike CGI, it permits a long-running service process to continue serving requests, thus avoiding delays in responding to requests due to setup overhead.

<span class="mw-page-title-main">LAMP (software bundle)</span> Acronym for a common web hosting solution

LAMP is an acronym denoting one of the most common software stacks for the web's most popular applications. Its generic software stack model has largely interchangeable components.

<span class="mw-page-title-main">Catalyst (software)</span>

Catalyst is an open source web application framework written in Perl, that closely follows the model–view–controller (MVC) architecture, and supports a number of experimental web patterns. It is written using Moose, a modern object system for Perl. Its design is heavily inspired by frameworks such as Ruby on Rails, Maypole, and Spring.

Web server software allows computers to act as web servers. The first web servers supported only static files, such as HTML, but now they commonly allow embedding of server side applications.

The Apache JServ Protocol (AJP) is a binary protocol that can proxy inbound requests from a web server through to an application server that sits behind the web server. AJP is a highly trusted protocol and should never be exposed to untrusted clients, which could use it to gain access to sensitive information or execute code on the application server.

Nginx is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. The software was created by Russian developer Igor Sysoev and publicly released in 2004. Nginx is free and open-source software, released under the terms of the 2-clause BSD license. A large fraction of web servers use Nginx, often as a load balancer.

Web2py is an open-source web application framework written in the Python programming language. Web2py allows web developers to program dynamic web content using Python. Web2py is designed to help reduce tedious web development tasks, such as developing web forms from scratch, although a web developer may build a form from scratch if required.

mod_lisp is an extension module for the Apache HTTP Server. It enables Apache to interface with application servers written in Common Lisp, making it possible to dynamically generate web pages and provide web applications with Common Lisp programs.

<span class="mw-page-title-main">Web server directory index</span> Index page of a websites directory

When an HTTP client requests a URL that points to a directory structure instead of an actual web page within the directory structure, the web server will generally serve a default page, which is often referred to as a main or "index" page.

<span class="mw-page-title-main">Slowloris (computer security)</span> Software for executing a denial-of-service attack

Slowloris is a type of denial of service attack tool which allows a single machine to take down another machine's web server with minimal bandwidth and side effects on unrelated services and ports.

mod_proxy is an optional module for the Apache HTTP Server.

<span class="mw-page-title-main">Plack (software)</span>

Plack is a Perl web application programming framework inspired by Rack for Ruby and WSGI for Python, and it is the project behind the PSGI specification used by other frameworks such as Catalyst and Dancer. Plack allows for testing of Perl web applications without a live web server.

HTTP/2 is a major revision of the HTTP network protocol used by the World Wide Web. It was derived from the earlier experimental SPDY protocol, originally developed by Google. HTTP/2 was developed by the HTTP Working Group of the Internet Engineering Task Force (IETF). HTTP/2 is the first new version of HTTP since HTTP/1.1, which was standardized in RFC 2068 in 1997. The Working Group presented HTTP/2 to the Internet Engineering Steering Group (IESG) for consideration as a Proposed Standard in December 2014, and IESG approved it to publish as Proposed Standard on February 17, 2015. The initial HTTP/2 specification was published as RFC 7540 on May 14, 2015.

References

  1. "FastCGI Specification". Open Market, Inc. 1996. Archived from the original on 19 January 2016.
  2. "FastCGI:A High-Performance Web Server Interface". Open Market, Inc. 1996. Archived from the original on 1 October 2010.
  3. Heinlein, Paul (1 November 1998). "FastCGI: Persistent Applications for Your Web Server". Linux Journal. Retrieved 4 October 2010.
  4. FastCGI apache module mod_fcgid
  5. Debian bug #450748: Please add support for TCP/IP FastCGI servers
  6. Issues with Apache 2.4 and PHP-FPM
  7. libapache-mod-fastcgi on Github
  8. "FastCGI – The Forgotten Treasure/ Section 2.3". Archived from the original on 2010-02-08. Retrieved 2006-02-21.
  9. The fastcgi transport — reverse_proxy (Caddyfile directive) — Caddy Documentation
  10. FastCGI for Cherokee
  11. FastCGI howto for Hiawatha
  12. 1 2 "FastCGI Support in Jetty". Archived from the original on 2020-03-24. Retrieved 2017-03-23.
  13. FastCGI for Lighttpd
  14. "FastCGI Extension for IIS6.0 – RTM". FastCGI for IIS. Microsoft. 2008-02-28. Retrieved 2008-02-29.
  15. "FastCGI Nginx module ngx_http_fastcgi_module". nginx.org. NGINX, Inc. Retrieved 20 June 2021.
  16. OpenBSD's httpd(8) initial commit
  17. "Technical sheet". Archived from the original on 2018-01-21. Retrieved 2016-09-19.
  18. Application Libraries, Development Kits
  19. "Matreshka". Archived from the original on 2018-01-20. Retrieved 2011-10-06.
  20. ExtPascal
  21. How to use FastCGI from Common Lisp
  22. Goanna Eiffel
  23. jFastCGI, a Java Servlet implementing FastCGI protocol
  24. node-fastcgi npm package
  25. There are several 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).
  26. "PHP: FastCGI Process Manager (FPM) - Manual".
  27. FasterCGI with HHVM
  28. Several Rust crates exist: A listener implementation is fastcgi, and fastcgi-client is a client implementation.
  29. REAL Studio Web Edition, builds web apps called via FastCGI Archived 2011-02-08 at the Wayback Machine