Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the CGI CPAN distribution.

Report information
The Basics
Id: 70609
Status: resolved
Priority: 0/
Queue: CGI

People
Owner: LEEJO [...] cpan.org
Requestors: dan [...] greywallsoftware.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: CGI::Fast not honoring ENV values unless in BEGIN
Download (untitled) / with headers
text/plain 948b
According to the POD, CGI::Fast honors the environment variables FCGI_SOCKET_PATH and FCGI_LISTEN_QUEUE. However, experimentally these variables only take effect if assigned in a BEGIN block prior to loading CGI::Fast. Without this, invoking the program causes it to simply run once and exit. eg. #!perl use CGI::Fast; local $ENV{FCGI_SOCKET_PATH} = ":9000"; local $ENV{FCGI_LISTEN_QUEUE} = 20; while ($q = CGI::Fast->new) { print $q->header; print "<html><body>The foo input is ", $q->param('foo'), "</body></html>"; } prints Content-Type: text/html; charset=ISO-8859-1 <html><body>The foo input is </body></html> on STDOUT and exits immediately. To fix this you have to change the code as follows: BEGIN { $ENV{FCGI_SOCKET_PATH} = ":9000"; $ENV{FCGI_LISTEN_QUEUE} = 20; } use CGI::Fast; I can't say whether this is a code or POD bug since I'm not sure what the original intent was, but it's definitely one or the other.
CC: undisclosed-recipients:;, Dan Dormont via RT <bug-cgi.pm [...] rt.cpan.org>
Subject: Re: [rt.cpan.org #70609] CGI::Fast not honoring ENV values unless in BEGIN
Date: Wed, 31 Aug 2011 10:00:08 -0400
To: bug-CGI.pm [...] rt.cpan.org
From: Mark Stosberg <mark [...] summersault.com>
Thanks for the report. This sounds like something to fix.
Download (untitled) / with headers
text/plain 1.5k
If I may add my $0.02... I believe the best internal fix is to delay the creation of the request until it is needed in new(). Something like this in the constructor... $request ||= create_fcgi_request(); return unless $request->Accept >= 0; And then create_fcgi_request is something like... sub create_fcgi_request { if( $ENV{FCGI_SOCKET_PATH} ) { my $path = $ENV{FCGI_SOCKET_PATH}; my $backlog = $ENV{FCGI_LISTEN_QUEUE} || 100; my $socket = FCGI::OpenSocket( $path, $backlog ); return FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%ENV, $socket, 1 ); } else { return FCGI::Request(); } } This will have the benefit of making the code work as currently documented and eliminates the awkward "configure before load" trap. In addition, because environment variables are an awkward way to configure a module from the inside, I'd suggest adding this alternative to the interface... use CGI::Fast socket_path => ':9000', listen_queue => '50'; This makes it impossible to set the configuration too late. These arguments would override the defaults and the environment variables. This is still a global set on module load, which can bring problems. Usually configuring the object, not the module, is better. But since CGI::Fast is only intended to be loaded once per CGI process it should be ok. And if it turns out to be necessary, an additional override can be added to the object constructor later.
Subject: Re: [rt.cpan.org #70609] CGI::Fast not honoring ENV values unless in BEGIN
Date: Thu, 01 Sep 2011 09:59:28 -0400
To: bug-CGI.pm [...] rt.cpan.org
From: Mark Stosberg <mark [...] summersault.com>
Download (untitled) / with headers
text/plain 1.6k
Show quoted text
> If I may add my $0.02... I believe the best internal fix is to delay the > creation of the request until it is needed in new(). Something like > this in the constructor... > > $request ||= create_fcgi_request(); > return unless $request->Accept >= 0; > > And then create_fcgi_request is something like... > > sub create_fcgi_request { > if( $ENV{FCGI_SOCKET_PATH} ) { > my $path = $ENV{FCGI_SOCKET_PATH}; > my $backlog = $ENV{FCGI_LISTEN_QUEUE} || 100; > my $socket = FCGI::OpenSocket( $path, $backlog ); > return FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, > \%ENV, $socket, 1 ); > } > else { > return FCGI::Request(); > } > } > > This will have the benefit of making the code work as currently > documented and eliminates the awkward "configure before load" trap. > > In addition, because environment variables are an awkward way to > configure a module from the inside, I'd suggest adding this alternative > to the interface... > > use CGI::Fast socket_path => ':9000', listen_queue => '50'; > > This makes it impossible to set the configuration too late. These > arguments would override the defaults and the environment variables. > > This is still a global set on module load, which can bring problems. > Usually configuring the object, not the module, is better. But since > CGI::Fast is only intended to be loaded once per CGI process it should > be ok. And if it turns out to be necessary, an additional override can > be added to the object constructor later.
Thanks for the input! We'll consider that solution. Mark
Download (untitled) / with headers
text/plain 240b
This issue has been copied to: https://github.com/leejo/CGI.pm/issues/90 please take all future correspondence there. This ticket will remain open but please do not reply here. This ticket will be closed when the github issue is dealt with.
Fixed, will go out with the next version.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.