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

I'm so close! I've written a few CGI scripts years ago, but I'm a perl weakling.

This code fails when run through FastCGI:

#!c:/perl/bin/perl use CGI::Fast;

With this error:

Error! Can't locate object method "FILENO" via package "FCGI::Stream" at C:/Perl/lib/CGI.pm line 822. Compilation failed in require at C:/Perl/lib/CGI/Fast.pm line 20. BEGIN failed--compilation aborted at C:/Perl/lib/CGI/Fast.pm line 20. Compilation failed in require at (eval 4) line 4. BEGIN failed--compilation aborted at (eval 4) line 4.

But, if I tell FastCGI to reference the script directly, the following code runs perfectly. It keeps the same PID across multiple calls, increments the counter as expected, etc.

#!c:/perl/bin/perl -w use strict; use CGI::Fast; my $count = 1; while (my $q = CGI::Fast->new) { print("Content-Type: text/plain\n\n"); print("Process ID: $$; Count is: " . ++$count); }

The difference is in the fcgiext.ini.

Here's the config that fails:

[Types] fcgi=FCGI [FCGI] ExePath=C:\perl\bin\perl.exe Arguments="-MFCGI::IIS=eval"

Here's the config that succeeds:

[Types] fcgi=FCGI [FCGI] ExePath=C:\perl\bin\perl.exe Arguments=d:\inetpub\cgi-bin\hello.fcgi

Of course, the config that succeeds will only run that one script, and that's a bad thing.

It seems evident I've misconfigured FastCGI somehow in such a way as when it calls my perl script, perl cannot build out its environment correctly. Any insights into what I might have done wrong in FastCGI? Is there some environmental argument I might be missing in perl?

Thanks!

Replies are listed 'Best First'.
Re: FastCGI on IIS 6 almost working. (fix)
by tye (Sage) on Aug 14, 2010 at 05:09 UTC

    You should file a bug against FastCGI. They need to add:

    sub FCGI::Stream::FILENO { return undef; }

    But you can just add that yourself. You can even add that one line to your own script and that'd likely fix that problem.

    I'm not sure what is triggering the difference. CGI.pm appears to be trying to binmode STDIN, STDOUT, and STDERR in the failing case. Fixing this problem might expose the next problem for the failing case, of course.

    - tye        

      Good guess. I applied the line you recommended, and now the system does not fail on compile. It also does not ever return. And even though I have it in eval mode, It doesn't spit out any clue what's happening behind the curtain. Is there any bright way trace what's happening in perl.exe?

      If I comment out my($q = CGI::Fast->new), then everything runs perfectly. And at present my test script does nothing with $q, so my problem is in the instantiation. From the shell it runs smoothly, too.

      Thanks, tye.