FASTCGI and Perl CGI.pm package - state problem solved

Nigel Metheringham (Nigel.Metheringham@theplanet.net)
Tue, 18 Jun 1996 12:57:20 +0100

Message-Id: <m0uVzPN-0006Y3C@dingo.theplanet.co.uk>
To: fastcgi-developers@openmarket.com
From: Nigel Metheringham <Nigel.Metheringham@theplanet.net>
Subject: FASTCGI and Perl CGI.pm package - state problem solved
Date: Tue, 18 Jun 1996 12:57:20 +0100

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  ]