Forum Moderators: coopster & phranque

Message Too Old, No Replies

FastCGI script not recognizing the query string

$ARGV[0] is empty

         

MichaelBluejay

6:15 am on Jun 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm trying to port my Perl scripts from .cgi to .fcgi, and I'm finding that my .fcgi script can't see the query string. For example, if I browse to:

http://example.com/script.fcgi?test

Then this script prints nothing:

#!/usr/bin/perl -w

use lib qw( /home/myhome/lib/perl/5.8.4 );
use FCGI;

while ( FCGI::accept() >= 0 ) {
print "Content-type:text/html\n\n";
print $ARGV[0];
}

Am I doing something wrong, or is this expected behavior, and if so there has to be a workaround, right? I can't see how FastCGI is viable if you can't pass info via the query string....

rocknbil

9:35 pm on Jun 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK I've never used this module, but ARGV is usually an argument vector for command line input. Is it possible query strings and post data are not even stored in @ARGV? Usually it's stored in a hash.

KevinADC

12:32 am on Jun 10, 2006 (gmt 0)

10+ Year Member



me too, never used it but but a quick search on CPAN turns up some documentation:

[search.cpan.org...]

lexipixel

2:43 am on Jun 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...never used it either.

This is just a guess:

Could it have something to do with .htaccess in regards to the ".fcgi" extension?

.

MichaelBluejay

11:56 pm on Jun 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've been using $ARGV[0] for years to get the query string in Perl .cgi scripts. It just ceases to work when the scripts are .fcgi instead.

There is nothing in my .htaccess file related to .fcgi (or to plain .cgi, for that matter).

KevinADC

12:42 am on Jun 11, 2006 (gmt 0)

10+ Year Member



did you check the FCGI documentation?

MichaelBluejay

8:03 am on Jun 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Of course. I didn't see anything that looked applicable. Do you know something I don't? Did I miss something?

KevinADC

6:56 pm on Jun 11, 2006 (gmt 0)

10+ Year Member



the sample code in the doc is like this:


use FCGI;

my $count = 0;
my $request = FCGI::Request();

while($request->Accept() >= 0) {
print("Content-type: text/html\r\n\r\n", ++$count);
}

I don't know if you have to implicitly use the Request() function first, but in your code you also have 'accept()' but in the documentation it's Accept() with an upper-case A.

In the doc it says:


FCGI::Request

Creates a request handle. It has the following optional parameters:

input perl file handle (default: \*STDIN)
output perl file handle (default: \*STDOUT)
error perl file handle (default: \*STDERR)

These filehandles will be setup to act as input/output/error on succesful Accept.

MichaelBluejay

9:37 pm on Jun 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have no idea what that means (the second quoted block).

But anyway, I found a solution: just use $ENV{QUERY_STRING} instead of $ARGV[0]. It's obvious in hindsight.

veesah

4:26 am on Jun 12, 2006 (gmt 0)

10+ Year Member



ARGV are arguments passed at command line

However, with FastCGI, the perl script is only launched once and following requests go through the FCGI loop. Hence, there is no ARGV.

CGI specification specifies QUERY_STRING environment variable as the correct method to get the query. FCGI emulates this between apache request and FCGI faked out environment