i have a site that lets people upload images relating to a particular topic. topics expire. and when they have been expired 24 hours, i'd like to remove them and delete the associate images.
I am trying to decide what event to use on my site to trigger this deletion. I can think of a few possibilities:
1) CRON job - not sure how to set this up. have no experience setting up cron jobs and would like to be able to write code in PHP
2) check every time a user visits a page - might this cause performance issues if we are checking EVERY time a user visits?
3) set up a random lottery type event upon every page visit. set up random event so cleanup is averaging perhaps one time in 100.
I'm leaning toward #3. I have a file called top.php that gets included by all my files. I reckon I might put something like this in top:
$random_number = rand(1, 100);
if ($random_number == 50) {
do_garbage_collection();
}
Can anyone see any down side to this? I figure if site traffic is low, cleanup might never happen--but on the other hand if site traffic is low cleanup won't really be necessary.
thoughts?