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

Dear Monks

I'm trying to get my first fast cgi app running

fcgi_test.fcgi:
use CGI::Fast qw(:standard); $COUNTER = 0; while (new CGI::Fast) { print header; print start_html("Fast CGI Rocks"); print h1("Fast CGI Rocks"), "Invocation number ",b($COUNTER++), " PID ",b($$),".", hr; print end_html; }
The apache part looks like
LoadModule fcgid_module /usr/lib/apache2/modules/mod_fcgid.so ScriptAlias /cgi-bin/ "/srv/perl/cgi-bin/" AddHandler fcgi-script .fcgi AddType application/x-httpd-fcgi .fcgi .... <VirtualHost *:80> ... <Directory /srv/perl/cgi-bin/> AllowOverride All <FilesMatch "\.fcgi$"> SetHandler cgi-script </FilesMatch> </Directory> ... </VirtaulHost>
Although the script runs fine, it doesn't count anything (its always zero). Also I cannot access things like $ENV{REMOTE_HOST}!

Any suggestions ?

Thnx
LuCa

UPDATE With the info provided below I was ablte to find the solutions
SetHandler fcgid-script
thnx again!!

Replies are listed 'Best First'.
Re: fcgi script not working as expected (apache)
by moritz (Cardinal) on Dec 12, 2008 at 14:44 UTC
    You can't access things like $ENV{REMOTE_HOST} because the environment variables are set on a per-process base, and there should be only one fastcgi instance per apache process, not per request.

    All this information is encapsulated in the CGI::Fast objects, so don't throw that object away as you do now in the header of your while-loop, but assign it to a variable instead.

    I don't know why your counter isn't increased, though.

      Most of the code I'm using comes from cpan! http://search.cpan.org/~lds/CGI.pm-3.42/CGI/Fast.pm
Re: fcgi script not working as expected (apache)
by Anonymous Monk on Dec 12, 2008 at 14:55 UTC
    <VirtualHost *:80> ... <Directory /srv/perl/cgi-bin/> AllowOverride All <FilesMatch "\.fcgi$"> SetHandler cgi-script </FilesMatch> </Directory> ... </VirtaulHost>
    Maybe you want SetHandler fastcgi-script??
Re: fcgi script not working as expected (apache)
by jeanluca (Deacon) on Dec 12, 2008 at 15:12 UTC
    I've modified one of the print statements into:
    " PID ",b($$),". remote host: ",$ENV{REMOTE_HOST},"\n<br>",join(" ",ke +ys %ENV),
    which now produces:
    Fast CGI Rocks Invocation number 0 PID 29716. remote host: SCRIPT_NAME SERVER_NAME SERVER_ADMIN HTTP_ACCEPT_ENCODING HTTP_CONNECT +ION REQUEST_METHOD HTTP_ACCEPT SCRIPT_URI SCRIPT_FILENAME SERVER_SOFT +WARE HTTP_ACCEPT_CHARSET QUERY_STRING REMOTE_PORT HTTP_USER_AGENT SER +VER_PORT SERVER_SIGNATURE HTTP_ACCEPT_LANGUAGE REMOTE_ADDR HTTP_KEEP_ +ALIVE SERVER_PROTOCOL HTTP_IF_NONE_MATCH PERL5LIB PATH REQUEST_URI GA +TEWAY_INTERFACE HTTP_IF_MODIFIED_SINCE SERVER_ADDR SCRIPT_URL DOCUMEN +T_ROOT HTTP_HOST UNIQUE_ID
    If I change my httpd.conf into
    SetHandler fastcgi-script
    I get a download popup-window
Re: fcgi script not working as expected (apache)
by Anonymous Monk on Dec 12, 2008 at 14:47 UTC
    Dump %ENV, my guess is you're not running under FCGI.