
Going Dynamic
When the Internet was created, it was all a bunch of text (and later some graphics) files. Things have changed a lot since then—the majority of websites today are not primarily static sites. Either the HTML itself is created by a Content Management System (CMS) or the site embeds applications in the static content. To allow two-way communication between the browser and a program running on a web server, and to generate the content dynamically on the server, the Common Gateway Interface (CGI) was created.
CGI is very simple. The server gets a request, sets up an environment, starts the CGI process and optionally (for HTTP POST requests) pipes the request content into the CGI process' standard input. The CGI process prints the response (including headers) to its standard output, from where it is forwarded to the user by the server.
The simplicity of CGI gave it a big advantage over embedding applications in the server (as is done with Microsoft's Active Server Pages or Sun Microsystems' Java Server Pages), as one could run a CGI application over any web server supporting it, thus giving web server and web application creators a motivation to implement CGI.
With the proliferation of CGI-capable servers and applications, the downside of CGI has become apparent. CGI spawns one process per request , which taxes the operating system, memory and CPU, and leaves no chance to cache data between requests, as each CGI process starts with a clean slate.
There have been some attempts to create a successor to CGI. Two of the most successful successors are implemented as Lighttpd modules: SCGI and FastCGI.
Up to and including version 1.4.20, Lighttpd came with a module for each interface: mod_cgi
for CGI, mod_scgi
for SCGI, and mod_fastcgi
for FastCGI. From version 1.5.0 onwards, these modules have ceased to exist, and mod_proxy_core
, a shared code base for all application and proxying interfaces, has been extended by backend modules: mod_scgi_backend
and mod_fastcgi_backend
. Still, as at the time of this writing, 1.4.20 is in active use by many, we will start with mod_cgi.