Henrik2
Henrik2

Reputation: 311

Perl fast CGI : do you ever exit the loop?

Consider the standard Perl fast CGI script:

#!/usr/bin/perl

use CGI::Fast;

# Init handler

while (my $cgi = CGI::Fast->new) 
{
# Handle request
}

# Do you ever get here?

Do I ever exit the loop and get a chance to do some cleanup?

What happens when the server throws out the test.fpl script because the time limit has been exceeded?

Upvotes: 4

Views: 413

Answers (1)

ikegami
ikegami

Reputation: 385986

Not normally, but it is possible.

CGI::Fast::new is:

sub new {
    my ($self, $initializer, @param) = @_;

    if ( ! defined $initializer ) {
        $Ext_Request ||= _create_fcgi_request( $in_fh,$out_fh,$err_fh );
        return undef unless $Ext_Request->Accept >= 0;
    }
    CGI->_reset_globals;
    $self->_setup_symbols(@CGI::SAVED_SYMBOLS) if @CGI::SAVED_SYMBOLS;
    return $CGI::Q = $self->SUPER::new($initializer, @param);
}

As you can see, it can return false if $Ext_Request->Accept (where $Ext_Request is an FGCI::Request object) returns a negative number.

Drilling down gets us to a one of two C functions called OS_Accept, one for unix, and one for Windows. They are primarily wrappers for the accept system call.

accept primarily fail if it's interrupted by a signal or if the process runs out of resources (sockets or memory). Most other reasons would be the result of a bug in the code.

Upvotes: 3

Related Questions