bakerjay has asked for the wisdom of the Perl Monks concerning the following question:

Hi I am trying to set up FastCGI, and have run into problems. When I run the script the first time, it works fine. When I run it again, it keeps the same CGI parameters (and so always loads the same page). Simplified down, my script looks like this -
#!/usr/bin/perl use CGI; use FCGI; use Data::Dumper; my $count = 0; my $request = FCGI::Request(); while($request->Accept() >= 0) { print("Content-type: text/html\r\n\r\n"); print "Hello world - count = $count\n"; my $q = new CGI; print "Name = " . $q->param("name") ; $count++; }
Running Apache 1.3.33 - relevant config is simple, just
FastCgiConfig -autoUpdate <Directory "/"> Options FollowSymLinks +ExecCGI AllowOverride None AddHandler fastcgi-script pl fpl fcgi </Directory>
So...how can I get the proper CGI params each time the page is loaded?

Thanks very much
Jay

Replies are listed 'Best First'.
Re: Not getting CGI parameters under FastCGI
by almut (Canon) on May 23, 2008 at 22:50 UTC

    I can confirm that behaviour. Particularly weird is that if you print out $ENV{QUERY_STRING}, you can actually see the current proper values being passed in via the URL (GET request) — the param() method, however, continues to return the first-time value unchanged. It apparently doesn't reparse the available new input.  It doesn't even help to explicitly call $q->delete("name") or $q->delete_all() at the end of the request cycle...

    Well, for the moment, I don't have a solution other than to suggest that you use CGI::Simple instead, which doesn't suffer from this problem (it's a CGI drop-in replacement for most things you typically need, i.e. you'd just do my $q = new CGI::Simple; and then call $q->param(...) etc. as usual).

      Hey, thanks - good to know I'm not just going crazy!
      Tried CGI::Simple, and as you say, it works fine. The application I'm trying to use this with uses CGI::Application, so might have to see if I can change that module to use CGI::Simple for now too...hmmm...I'll see how I go.
      Cheers
      Jay
        Actually, turns out my CGI::Application was something entirely different...in trying to reduce it to a test case, I found a new problem! Grr..

        Anyway...main problem was that under CGI::Application::FastCGI, I was not releasing the database connection (was no need under normal CGI, it just released itself...), so then trying to recreate it failed miserably.

        So...thanks for your help, think I'm all sorted now.
        Jay

Re: Not getting CGI parameters under FastCGI
by Anonymous Monk on May 24, 2008 at 08:26 UTC
    Upgrade to latest CGi.pm or try use CGI::Fast;
      Tried upgrading CGI.pm (from v1.7601 to v1.9205), but didn't make any difference. Haven't tried CGI::Fast, but CGI::Simple (see above) seems to work fine.

      Thanks very much
      Jay