The HTTP specification states that all headers must be terminated with both a carriage-return (hex 0D) and a linefeed (hex 0A)
CR/LF pair), and that the last header in a stream must be followed by a blank line, and also terminated with a
The MIME header at the beginning of a CGI program usually has two
CR/LF pairs at the end of it.
The MIME header that is sent by the CGI program will actually be combined with a set of headers that the HTTP server will send to the client before sending the body of the data.
By default, the mod_cgi module is used to handle CGI content in Apache. The MIME type of the file, as well as its location, define whether or not mod_cgi will be invoked to handle the request. The location must fall within a directory defined as ScriptAlias.
When mod_cgi executes a CGI script, Apache forks a new process containing the interpreter for the CGI program.
Since this is a course on Perl, it means that the Perl interpreter is loaded each time a CGI program is executed.
The CGI program itself is compiled on each execution as well.
Any database connections and other necessities are also created for each execution. Naturally, this forking, loading the interpreter, and compiling the program have a cost. On busy systems, the resource cost of running a CGI program can make the application unacceptably slow. Where mod_cgi must load the Perl interpreter with each invocation of the CGI script, mod_perl embeds the Perl interpreter directly into the Apache child process. This means that the Perl interpreter is loaded only once for each child process, rather than once for each execution of the CGI program. mod_perl uses a couple of methods to execute Perl scripts. One of these methods compiles the program only once, when it is first used.
mod_perl is just one method for speeding up execution of
CGI programs. Another method is by using the FastCGI module.
To find out more about FastCGI, visit FastCGI