Re: Cleaning up automatically when leaving a page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Mary Anderson wrote:
Hi all,

I have a php application for which I have a page which creates temporary junk and puts it into a persistent store (in this case a postgres database, but that is beside the point.)

I have a Save button which puts the stuff I really want into the persistent store and cleans up the temporary junk. I have a Cancel button which only cleans up the temporary junk.

I would really like to have the cleanup code run anytime a user leaves the page without hitting the Save button. Is there anyway to do this? I.e. have php code called conditionally on exiting the page?

Thanks
Mary


I do a similar thing and put a unix timestamp on the temporary database.
A cron job run once a day calls a page that deletes anything in the temporary database that has a timestamp > 24 hours old.

You don't have to do it with a cron job - you can also have the function that writes to the table delete anything older than X hours if you don't have facilities to cron (though you can run the cron job from any machine, doesn't need to run on the server)

something like this

<?php
require('dbconnect.inc.php');
$expire = time() - (24 * 60 * 60);
$sql = "DELETE FROM temporary WHERE stamp < $expire";
mysql_query($sql);
?>

The security of who can access it isn't important, as it only deletes what you no longer want anyway and it returns no data to the browser.

Write a shell script that fetches it via wget and have cron execute it daily.

Maybe there's a better way, but it works for me.

For temporary files on the filesystem, I use http://linux.about.com/library/cmd/blcmdl8_tmpwatch.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux