For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > May 2007 > cleaning up as application ends









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cleaning up as application ends
Mary Anderson

2007-05-12, 6:55 pm


I would like to perform some clean up at various points in my application.
Here is one of them.

if ($pageName eq 'CSV'){
my $made_and_stuffed = make_and_stuff_query($pageName);
if ($made_and_stuffed == 1){
my $pathName = execute_CSV_query($pageName);
print a({-href=>$pathName}, 'Open CSV File'), hr;
}
}
On returning from viewing the file, or on hitting the submit button to go
to the next page, or on exiting the application I would like to get rid of
this file (using unlink, of course) Perl's END should do the trick, but I
find that it has rather odd notions of just what constitutes the END of the
application.
Although this particular file can be unlinked anytime after it has been
opened, I do have some clean up jobs which can be performed only when the
application exits. END, which has been tried, really does not work for this!

Thanks,
Mary Anderson
Mumia W.

2007-05-12, 9:55 pm

On 05/12/2007 05:37 PM, Mary Anderson wrote:
> I would like to perform some clean up at various points in my application.
> Here is one of them.
>
> if ($pageName eq 'CSV'){
> my $made_and_stuffed = make_and_stuff_query($pageName);
> if ($made_and_stuffed == 1){
> my $pathName = execute_CSV_query($pageName);
> print a({-href=>$pathName}, 'Open CSV File'), hr;
> }
> }
> On returning from viewing the file, or on hitting the submit button to go
> to the next page, or on exiting the application I would like to get rid of
> this file (using unlink, of course) Perl's END should do the trick, but I
> find that it has rather odd notions of just what constitutes the END of the
> application.
> Although this particular file can be unlinked anytime after it has been
> opened, I do have some clean up jobs which can be performed only when the
> application exits. END, which has been tried, really does not work for this!
>
> Thanks,
> Mary Anderson
>


END blocks should work properly unless you're running under mod_perl. If
you using a mod_perl environment, then special considerations must be made:

http://perl.apache.org/docs/1.0/gui...html#END_blocks

Mary Anderson

2007-05-13, 6:55 pm


>Mumia,

Thanks for the mod_perl tip. That 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








On 05/12/2007 05:37 PM, Mary Anderson wrote:
> application.
> go
> of
> but I
> the
> the
> this!
>
> END blocks should work properly unless you're running under mod_perl. If
> you using a mod_perl environment, then special considerations must be
> made:
>
> http://perl.apache.org/docs/1.0/gui...html#END_blocks
>
>
> --
> To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
> For additional commands, e-mail: beginners-cgi-help@perl.org
> http://learn.perl.org/
>
>

Mumia W.

2007-05-14, 6:55 pm

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/gui...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.


Ererbur8

2007-05-25, 9:30 pm

Hardcore sex movie! Free download!
http://www.incredible-asians-online...dicked_hard.avi
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com