Re: FASTCGI and Perl CGI.pm package - state problem solved

Lincoln D. Stein (lstein@genome.wi.mit.edu)
Tue, 18 Jun 1996 09:38:48 -0500

Message-Id: <v02140301adec6cf86a0e@[18.157.0.189]>
Date: Tue, 18 Jun 1996 09:38:48 -0500
To: CGI-perl@webstorm.com
From: lstein@genome.wi.mit.edu (Lincoln D. Stein)
Subject: Re: FASTCGI and Perl CGI.pm package - state problem solved

I'm going to build in support for FastCGI now that I know about it.  I'll
probably encapsulate fast cgi's accept() routine in a CGI method call.
While I'm at it, I plan to fix up CGI.pm to work correctly with Apache's
perl module.

Lincoln

At 12:57 PM 6/18/96, Nigel Metheringham wrote:
>The fastcgi stuff was not working at all well with Lincoln Stein's
>CGI.pm package (and probably the CGI modules as well).  I am using
>version 2.20, but the changelist for 2.21 indicates that the problem
>is probably still there, and probably has been for a while.
>
>Since I have sent this to both the CGI and FASTCGI lists I'll give a
>bit more background...
>
>Fastcgi gives a speed up on CGI by starting the script only once and
>running it in a loop where each loop is equivalent to a normal CGI
>invocation.  This saves on the exec and startup costs of a script -
>which should be a big win for perl.
>
>The drawback is that you need to be *very* careful about what state
>you keep to prevent bleeding of information between sessions.
>
>The problem was that using the CGI.pm module state was being *very*
>persistantly being kept - I just couldn't get rid of it, even by
>ensuring that all variables had appropriate scope and even explicitly
>being undef-ed after each loop.
>
>It appears that CGI.pm has a cunning scheme to allow you get the form
>data more than once in a program - always supplying the same data
>back.  This is acheived by stashing a copy of the data in
>@CGI::QUERY_PARAM
>
>I found that if I added an
>        undef(@CGI::QUERY_PARAM);
>to the end of my loop, things worked much more as expected.  I am
>still testing this, but it appears to be a fix for now.
>
>Would it be possible for a method to be added to CGI.pm to completely
>reset all the state, including @CGI::QUERY_PARAM, or some form of
>FCGI awareness be added to it so that it works right...?
>
>An FCGI program would now look something like this...
>    #!/usr/bin/fperl
>
>    use strict;
>    use FCGI;
>    use CGI;
>
>    my($Count) = 0;
>
>    while(FCGI::accept() >= 0) {
>        my($Cgi) = new CGI;
>
>        # Normal CGI routines....
>        # Normal HTML output etc...
>
>        $Count++;
>        undef(@CGI::QUERY_PARAM);
>    }
>
>        Nigel.
>
>--
>[ Nigel.Metheringham@theplanet.net   - Unix Applications Engineer ]
>[ *Views expressed here are personal and not supported by PLAnet* ]
>[ PLAnet Online : The White House          Tel : +44 113 251 6012 ]
>[ Melbourne Street, Leeds LS2 7PS UK.      Fax : +44 113 2345656  ]

========================================================================
Lincoln Stein, M.D.,Ph.D.                       lstein@genome.wi.mit.edu
Director: Informatics Core
MIT Genome Center                               (617) 252-1916
Whitehead Institute for Biomedical Research     (617) 252-1902 FAX
One Kendall Square
Cambridge, MA 02139
================ http://www-genome.wi.mit.edu/~lstein ===================