Using Fastcgi with Apache HTTP Server

Using Fastcgi with Apache HTTP Server

Using FastCGI with Apache HTTP Server Jeff Trawick The world of FastCGI FastCGI with Using FastCGI with Apache HTTP Server Apache httpd Comparisons between the contenders Jeff Trawick Configuration Future November 3, 2010 Table of Contents Using FastCGI with Apache HTTP Server Jeff Trawick 1 The world of FastCGI The world of FastCGI FastCGI with 2 FastCGI with Apache httpd Apache httpd Comparisons between the contenders 3 Comparisons between the contenders Configuration Future 4 Configuration 5 Future Implemented for most web servers. Implemented for most programming languages and a number of frameworks. FastCGI Using FastCGI with Apache HTTP Server Jeff Trawick The world of FastCGI A protocol for communicating between a web server and FastCGI with Apache httpd persistent application processes which can handle any of Comparisons several different phases of requests. between the contenders Configuration Future Implemented for most programming languages and a number of frameworks. FastCGI Using FastCGI with Apache HTTP Server Jeff Trawick The world of FastCGI A protocol for communicating between a web server and FastCGI with Apache httpd persistent application processes which can handle any of Comparisons several different phases of requests. between the contenders Implemented for most web servers. Configuration Future FastCGI Using FastCGI with Apache HTTP Server Jeff Trawick The world of FastCGI A protocol for communicating between a web server and FastCGI with Apache httpd persistent application processes which can handle any of Comparisons several different phases of requests. between the contenders Implemented for most web servers. Configuration Implemented for most programming languages and a Future number of frameworks. input stream for request body output stream for response headers and body output stream for log messages But binary encoded on a stream connection or pipe (Windows). FastCGI process waits repeatedly for new connections. Fast CGI Using FastCGI with Apache HTTP Server Jeff Trawick The world of Inputs and outputs are similar to CGI: FastCGI environment variables FastCGI with Apache httpd CONTENT LENGTH, SCRIPT NAME, etc. Comparisons between the contenders Configuration Future output stream for response headers and body output stream for log messages But binary encoded on a stream connection or pipe (Windows). FastCGI process waits repeatedly for new connections. Fast CGI Using FastCGI with Apache HTTP Server Jeff Trawick The world of Inputs and outputs are similar to CGI: FastCGI environment variables FastCGI with Apache httpd CONTENT LENGTH, SCRIPT NAME, etc. Comparisons between the input stream for request body contenders Configuration Future output stream for log messages But binary encoded on a stream connection or pipe (Windows). FastCGI process waits repeatedly for new connections. Fast CGI Using FastCGI with Apache HTTP Server Jeff Trawick The world of Inputs and outputs are similar to CGI: FastCGI environment variables FastCGI with Apache httpd CONTENT LENGTH, SCRIPT NAME, etc. Comparisons between the input stream for request body contenders output stream for response headers and body Configuration Future But binary encoded on a stream connection or pipe (Windows). FastCGI process waits repeatedly for new connections. Fast CGI Using FastCGI with Apache HTTP Server Jeff Trawick The world of Inputs and outputs are similar to CGI: FastCGI environment variables FastCGI with Apache httpd CONTENT LENGTH, SCRIPT NAME, etc. Comparisons between the input stream for request body contenders output stream for response headers and body Configuration Future output stream for log messages Fast CGI Using FastCGI with Apache HTTP Server Jeff Trawick The world of Inputs and outputs are similar to CGI: FastCGI environment variables FastCGI with Apache httpd CONTENT LENGTH, SCRIPT NAME, etc. Comparisons between the input stream for request body contenders output stream for response headers and body Configuration Future output stream for log messages But binary encoded on a stream connection or pipe (Windows). FastCGI process waits repeatedly for new connections. Raw CGI Using FastCGI with Apache HTTP Server Jeff Trawick int main(int argc, char **argv) The world of { FastCGI extern char **environ; FastCGI with /* environ is {"CONTENT_LENGTH=105", Apache httpd "SCRIPT_NAME=/path/to/foo.fcgi", etc. } */ Comparisons const char *cl_str; between the contenders Configuration if ((cl_str = getenv("CONTENT_LENGTH")) { read(FILENO_STDIN,,); /* request body */ Future } write(STDOUT_FILENO,,); /* response headers * and body */ write(STDERR_FILENO,,); /* to web server log */ } Raw FastCGI Using FastCGI with Apache int main(int argc, char **argv) HTTP Server { Jeff Trawick socket(); bind(); listen(); while (1) { The world of FastCGI int cl = accept(); FastCGI with read(cl, buf); Apache httpd |00000 0101000100080000 0001000000000000 ........ ........| Comparisons |00010 0104000100190000 090e485454505f48 ........ ..HTTP_H| between the contenders |00020 4f53543132372e30 2e302e313a383038 OST127.0 .0.1:808| |00030 3101040001002000 000f0f485454505f 1..... ...HTTP_| Configuration |00040 555345525f414745 4e54417061636865 USER_AGE NTApache| Future |00050 42656e63682f322e 3301040001001000 Bench/2. 3.......| |00060 000b03485454505f 4143434550542a2f ...HTTP_ ACCEPT*/| write(cl, buf); |00000 01060001041a0600 436f6e74656e742d ........ Content-| |00010 547970653a207465 78742f706c61696e Type: te xt/plain| |00020 0a0a787878787878 7878787878787878 ..xxxxxx xxxxxxxx| |00030 7878787878787878 7878787878787878 xxxxxxxx xxxxxxxx| close(cl); } } Raw FastCGI Using FastCGI with Apache HTTP Server How the datastream is defined: Jeff Trawick version | 1 byte, always 1 The world of FastCGI type | 1 byte, stuff like begin-request, abort-request, FastCGI with params, stdin-data, stdout-data, etc. Apache httpd Comparisons request id | 2 byte request identifier between the contenders content length | 2 byte length of bundled data Configuration padding length | 1 byte length of padding data Future the data (0{64k bytes) the padding (0{255 bytes) |0101000100080000 0001000000000000 ........ ........| |0104000100190000 090e485454505f48 ........ ..HTTP_H| Programming support Using FastCGI with Apache HTTP Server Jeff Trawick After all, nobody would want to reinvent that protocol. The world of FastCGI FastCGI protocol libraries are available for use with Perl, FastCGI with Apache httpd Python, Ruby, C, etc., often based on the C library from Comparisons Open Market. between the contenders Code to the API to implement a FastCGI application. Configuration With some APIs, a properly coded FastCGI app will also Future work as plain CGI. PHP supports it transparently. Some frameworks support it transparently. Dual-mode CGI/FastCGI Perl script: use CGI::Fast; while (my $q = CGI::Fast->new) { $mode = $q->param('mode'); print $q->header(-type => 'text/html'); print $q->start_html('hello, world'), $q->h1('hello, world'), $q->end_html; } But beware of unintentionally saved state. Perl example, moving from CGI to FastCGI Using FastCGI CGI-only Perl script: with Apache HTTP Server use CGI; Jeff Trawick my $q = CGI->new; $mode = $q->param('mode'); The world of print $q->header(-type => 'text/html'); FastCGI print $q->start_html('hello, world'), FastCGI with $q->h1('hello, world'), Apache httpd $q->end_html; Comparisons } between the contenders Configuration Future But beware of unintentionally saved state. Perl example, moving from CGI to FastCGI Using FastCGI CGI-only Perl script: with Apache HTTP Server use CGI; Jeff Trawick my $q = CGI->new; $mode = $q->param('mode'); The world of print $q->header(-type => 'text/html'); FastCGI print $q->start_html('hello, world'), FastCGI with $q->h1('hello, world'), Apache httpd $q->end_html; Comparisons } between the contenders Dual-mode CGI/FastCGI Perl script: Configuration Future use CGI::Fast; while (my $q = CGI::Fast->new) { $mode = $q->param('mode'); print $q->header(-type => 'text/html'); print $q->start_html('hello, world'), $q->h1('hello, world'), $q->end_html; } Perl example, moving from CGI to FastCGI Using FastCGI CGI-only Perl script: with Apache HTTP Server use CGI; Jeff Trawick my $q = CGI->new; $mode = $q->param('mode'); The world of print $q->header(-type => 'text/html'); FastCGI print $q->start_html('hello, world'), FastCGI with $q->h1('hello, world'), Apache httpd $q->end_html; Comparisons } between the contenders Dual-mode CGI/FastCGI Perl script: Configuration Future use CGI::Fast; while (my $q = CGI::Fast->new) { $mode = $q->param('mode'); print $q->header(-type => 'text/html'); print $q->start_html('hello, world'), $q->h1('hello, world'), $q->end_html; } But beware of unintentionally saved state. Web server support for FastCGI applications Using FastCGI with Apache HTTP Server Jeff Trawick The world of FastCGI FastCGI with Apache httpd Available for most web servers, including Apache httpd, Comparisons IIS, Lighttpd, nginx, iPlanet, and others between the contenders Typically implemented as a shared library (plug-in module) Configuration which can be loaded if the feature is desired Future Who would have thought Using FastCGI with Apache HTTP Server Jeff Trawick The world of FastCGI FastCGI with Apache httpd Comparisons such an old and obvious extension to CGIs is still relevant between the contenders a web lifetime later? Configuration Future History Using FastCGI with Apache HTTP Server Jeff Trawick The FastCGI protocol was originally developed in The world of 1995{1996 for a web server from Open Market, perhaps in FastCGI response to the NSAPI programming model

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    110 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us