Re: fastCGI, memory leaks etc

Mark Brown (mbrown@openmarket.com)
Mon, 19 Aug 1996 11:06:46 -0400

Message-Id: <199608191506.LAA15498@breckenridge.openmarket.com>
To: fastcgi-developers@openmarket.com
Subject: Re: fastCGI, memory leaks etc 
In-Reply-To: <321878F5.4B081A7D@cursci.co.uk> 
Date: Mon, 19 Aug 1996 11:06:46 -0400
From: Mark Brown <mbrown@openmarket.com>


Michael Smith writes:

    I have tried achieving the desired effect with the following piece of
    perl:

    my($count)=0;

    while (FCGI::accept() >= 0) {
        $count++;
        print "Content-type: text/html\n\nCount=$count\n";
        if ($count > 3) {
            exit(0);
        }
    }

    But this gives me a server error every forth time.
    Any way of avoiding this undesirable effect would be much appreciated.

You need to call FCGI::finish before you exit:

    while (FCGI::accept() >= 0) {
        $count++;
        print "Content-type: text/html\n\nCount=$count\n";
        if ($count > 3) {
            FCGI::finish();
            exit(0);
        }
    }

FCGI::finish completes the current request without accepting a new
one.  The first person to ask for this feature was Rujith S. de Silva
(http://www.fastcgi.com/mail-archive/0050.html);
FCGI::finish was added in version 1.5 of the kit
(http://www.fastcgi.com/mail-archive/0069.html).

Privately, Rujith reported having trouble with a program like

    my($count)=0;
    while ($count < 4 && FCGI::accept () >= 0) {
        print "Content-type: text/html\n\nCount=$count\n";
        FCGI::finish();
        ++$count;
    }
    exit (0);

which *should* work just fine.  If you try this form and have problems
please let me know.

    --mark