Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.3 KiB

  1. package CGI::Fast;
  2. # See the bottom of this file for the POD documentation. Search for the
  3. # string '=head'.
  4. # You can run this file through either pod2man or pod2html to produce pretty
  5. # documentation in manual or html file format (these utilities are part of the
  6. # Perl 5 distribution).
  7. # Copyright 1995,1996, Lincoln D. Stein. All rights reserved.
  8. # It may be used and modified freely, but I do request that this copyright
  9. # notice remain attached to the file. You may modify this module as you
  10. # wish, but if you redistribute a modified version, please attach a note
  11. # listing the modifications you have made.
  12. # The most recent version and complete docs are available at:
  13. # http://www.genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html
  14. # ftp://ftp-genome.wi.mit.edu/pub/software/WWW/
  15. $CGI::Fast::VERSION='1.01';
  16. use CGI;
  17. use FCGI;
  18. @ISA = ('CGI');
  19. # workaround for known bug in libfcgi
  20. while (($ignore) = each %ENV) { }
  21. # override the initialization behavior so that
  22. # state is NOT maintained between invocations
  23. sub save_request {
  24. # no-op
  25. }
  26. # New is slightly different in that it calls FCGI's
  27. # accept() method.
  28. sub new {
  29. my ($self, $initializer, @param) = @_;
  30. unless (defined $initializer) {
  31. return undef unless FCGI::accept() >= 0;
  32. }
  33. return $CGI::Q = $self->SUPER::new($initializer, @param);
  34. }
  35. 1;
  36. =head1 NAME
  37. CGI::Fast - CGI Interface for Fast CGI
  38. =head1 SYNOPSIS
  39. use CGI::Fast qw(:standard);
  40. $COUNTER = 0;
  41. while (new CGI::Fast) {
  42. print header;
  43. print start_html("Fast CGI Rocks");
  44. print
  45. h1("Fast CGI Rocks"),
  46. "Invocation number ",b($COUNTER++),
  47. " PID ",b($$),".",
  48. hr;
  49. print end_html;
  50. }
  51. =head1 DESCRIPTION
  52. CGI::Fast is a subclass of the CGI object created by
  53. CGI.pm. It is specialized to work well with the Open Market
  54. FastCGI standard, which greatly speeds up CGI scripts by
  55. turning them into persistently running server processes. Scripts
  56. that perform time-consuming initialization processes, such as
  57. loading large modules or opening persistent database connections,
  58. will see large performance improvements.
  59. =head1 OTHER PIECES OF THE PUZZLE
  60. In order to use CGI::Fast you'll need a FastCGI-enabled Web
  61. server. Open Market's server is FastCGI-savvy. There are also
  62. freely redistributable FastCGI modules for NCSA httpd 1.5 and Apache.
  63. FastCGI-enabling modules for Microsoft Internet Information Server and
  64. Netscape Communications Server have been announced.
  65. In addition, you'll need a version of the Perl interpreter that has
  66. been linked with the FastCGI I/O library. Precompiled binaries are
  67. available for several platforms, including DEC Alpha, HP-UX and
  68. SPARC/Solaris, or you can rebuild Perl from source with patches
  69. provided in the FastCGI developer's kit. The FastCGI Perl interpreter
  70. can be used in place of your normal Perl without ill consequences.
  71. You can find FastCGI modules for Apache and NCSA httpd, precompiled
  72. Perl interpreters, and the FastCGI developer's kit all at URL:
  73. http://www.fastcgi.com/
  74. =head1 WRITING FASTCGI PERL SCRIPTS
  75. FastCGI scripts are persistent: one or more copies of the script
  76. are started up when the server initializes, and stay around until
  77. the server exits or they die a natural death. After performing
  78. whatever one-time initialization it needs, the script enters a
  79. loop waiting for incoming connections, processing the request, and
  80. waiting some more.
  81. A typical FastCGI script will look like this:
  82. #!/usr/local/bin/perl # must be a FastCGI version of perl!
  83. use CGI::Fast;
  84. &do_some_initialization();
  85. while ($q = new CGI::Fast) {
  86. &process_request($q);
  87. }
  88. Each time there's a new request, CGI::Fast returns a
  89. CGI object to your loop. The rest of the time your script
  90. waits in the call to new(). When the server requests that
  91. your script be terminated, new() will return undef. You can
  92. of course exit earlier if you choose. A new version of the
  93. script will be respawned to take its place (this may be
  94. necessary in order to avoid Perl memory leaks in long-running
  95. scripts).
  96. CGI.pm's default CGI object mode also works. Just modify the loop
  97. this way:
  98. while (new CGI::Fast) {
  99. &process_request;
  100. }
  101. Calls to header(), start_form(), etc. will all operate on the
  102. current request.
  103. =head1 INSTALLING FASTCGI SCRIPTS
  104. See the FastCGI developer's kit documentation for full details. On
  105. the Apache server, the following line must be added to srm.conf:
  106. AddType application/x-httpd-fcgi .fcgi
  107. FastCGI scripts must end in the extension .fcgi. For each script you
  108. install, you must add something like the following to srm.conf:
  109. AppClass /usr/etc/httpd/fcgi-bin/file_upload.fcgi -processes 2
  110. This instructs Apache to launch two copies of file_upload.fcgi at
  111. startup time.
  112. =head1 USING FASTCGI SCRIPTS AS CGI SCRIPTS
  113. Any script that works correctly as a FastCGI script will also work
  114. correctly when installed as a vanilla CGI script. However it will
  115. not see any performance benefit.
  116. =head1 CAVEATS
  117. I haven't tested this very much.
  118. =head1 AUTHOR INFORMATION
  119. Copyright 1996-1998, Lincoln D. Stein. All rights reserved.
  120. This library is free software; you can redistribute it and/or modify
  121. it under the same terms as Perl itself.
  122. Address bug reports and comments to: lstein@cshl.org
  123. =head1 BUGS
  124. This section intentionally left blank.
  125. =head1 SEE ALSO
  126. L<CGI::Carp>, L<CGI>
  127. =cut