Re: Perl/Cgi : how to delete file after leaving original myscript.cgi?
by xorl (Deacon) on Jan 03, 2005 at 15:18 UTC
|
I think you're going to be better off just setting up a cron job to delete the files if they haven't been accessed within x number of hours.
You could try...To the page's body tag you could add some JavaScript (onUnload=byebye()) which would force the calling of another script which would delete the page. However in the real world there are just too many ways that this wouldn't work.
| [reply] |
Re: Perl/Cgi : how to delete file after leaving original myscript.cgi?
by skx (Parson) on Jan 03, 2005 at 15:20 UTC
|
The short answer is that you cannot, HTTP is stateless so you have no notification that any given connection request is the last one.
Perhaps the best thing to do is to setup a timed job that will delete all binary files which are older than 30 minutes in a cronjob?
This is my 100th post
| [reply] |
Re: Perl/Cgi : how to delete file after leaving original myscript.cgi?
by Fletch (Bishop) on Jan 03, 2005 at 15:26 UTC
|
You might want to look at using some descendant of Cache::Cache and let it handle expiring old items after n minutes or hours.
| [reply] |
Re: Perl/Cgi : how to delete file after leaving original myscript.cgi?
by mpeters (Chaplain) on Jan 03, 2005 at 15:21 UTC
|
There are a couple of ways that this can be done. The first that comes to my mind is to use some sort of cron job that would simply delete old files.
From the cgi script there is not a way to tell if the user doesn't come back (or goes to another page). Plus, I don't think you would want to know this. For instance if they have multiple windows or tabbed browsing, it's quite possible that they would go to another site and then back to your script. | [reply] |
Re: Perl/Cgi : how to delete file after leaving original myscript.cgi?
by sgifford (Prior) on Jan 03, 2005 at 17:42 UTC
|
While a page is still loading, you can test to see if the client is still there by printing something to the socket and seeing if you get SIGPIPE or similar. Once the page has stopped loading, there's no way to tell except to use a timeout and make some educated guesses. | [reply] [d/l] |
Re: Perl/Cgi : how to delete file after leaving original myscript.cgi?
by r34d0nl1 (Pilgrim) on Jan 03, 2005 at 18:20 UTC
|
One way would be to send a request to myscript3.pl?file2delete=nnn (for example) to delete the nnn file.
It can be done using JavaScript like in OnBlur or OnClose methods.
Anyway the user may not allow you to open a new window, delete the file and then close the window, so I agree that
the unique way to be sure you can delete the file is to put a process that will delete the files created based on last access time, for example. | [reply] |
Re: Perl/Cgi : how to delete file after leaving original myscript.cgi?
by CountZero (Bishop) on Jan 03, 2005 at 20:36 UTC
|
Can't you put both scipts into one? That way you both generate the data and deal with it and then after the page has been sent to the user, delete the data.
CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] |
|
|
mmm , to generate the hash data takes 5 seconds. If I included in the original, it would take longer each time the user makes a choice and have to reevaluate the script again.
| [reply] |
|
|
In that case, you will have to:- find a way to speed-up the generation of the hash; or
- go for the "cron job" approach; or
- do something totally different (but it is difficult to help you here as we have no idea what exactly you are trying to do -- could you post some code or perhaps a link to the web-site where the script is running?)
CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] |