Re: cleaning up as application ends

[email protected] ("Mumia W.")
Newsgroups perl.beginners.cgi
Message-ID <[email protected]>
On 05/13/2007 05:32 PM, Mary Anderson wrote:
> Mumia,
>    Thanks for the mod_perl tip.  That [http://perl.apache.org/docs/1.0/guide/porting.html#END_blocks] seems to say that the code in the END 
> block will be executed when the server stops, not when the session comes to 
> an end.
> 
>    My END blocks are executed well before the session comes to an end.
> 
>    If I do something like this:
> 
>     print header;
>     END {print "Ending Now", hr}
>     
>     my $login = param('Login');
> 
>     my $page_name = param('Go');
>     
>     if ($page_name eq 'Logged In'){
>         print "a({-href=>"./fubar", "fubar"});
>     }
>    
>     if (!$page_name){
>         print submit ({-name=>'Go', -Label = 'Logged In');
>     }
> 
> Then what happens when this (not real) code runs is that I type in login, 
> hit the Logged In button, fubar is printed and then I see "Ending Now".
> 
> My session is still running.  I want code executed when the session closes. 
> Is it possible to do this in cgi?  (I am beginning to think not.)
> 
> mary
> 

I'm assuming that you when you say session, you mean a group of requests 
that are associated with a single user. One option would be to execute 
the cleanup code when the user logs out; another option would be to 
periodically search for expired sessions and clean them up.

If you're using CGI::Session, you can probably subclass it and override 
the delete method to perform you cleanup operations (as well as call the 
superclass delete method).

You haven't confirmed what CGI-like environment you're using: mod_perl, 
fastcgi or regular CGI. Look at the documentation for the CGI and 
session management libraries you're using; they should describe how to 
register cleanup code.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.