Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to manage temp files created by CGIs?

Status
Not open for further replies.

lichtjiang

Programmer
Feb 26, 2007
39
US
Usually, a CGI would create many temp files. For example, it may dynamically create many maps, which do not exist on disks. So, after a web browser session expires, some of these files will be no use any more. But some (e.g., a map for recent climate) may serve multiple requests at different times. So, there may exist need to keep some of these files for a certain period of time. In this regard, how to manage them?

Thanks!
 
If you're talking about Perl, you could use the stat() function to find out the creation and access times, and delete files that haven't been used in a long time.

Code:
my @stat = stat("tempfile.tmp");
my $atime = $stat[8];
my $mtime = $stat[9];

# if it hasn't been accessed in 24 hours...
if (time() - $atime > (60*60*24)) {
   # delete it
   unlink ("tempfile.tmp");
}

# or if it was last modified 30 days ago...
if (time() - $mtime > (60*60*24*30)) {
   unlink ("tempfile.tmp");
}

-------------
Cuvou.com | The NEW Kirsle.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top