FASTCGI and Perl package - state problem solved

Nigel Metheringham (
Tue, 18 Jun 1996 12:57:20 +0100

Message-Id: <>
From: Nigel Metheringham <>
Subject: FASTCGI and Perl 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 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 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 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 

I found that if I added an
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 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...

    use strict;
    use FCGI;
    use CGI;

    my($Count) = 0;

    while(FCGI::accept() >= 0) {
	my($Cgi) = new CGI;

	# Normal CGI routines....
	# Normal HTML output etc...



[   - 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  ]