0

I've looked into this, and I've found out about Cron jobs - but the thing is that it only has to run once ever.

Background: My users can create something that expires - and they choose when it expires.

One of my solutions: Maybe I don't have to expire it on that day - whenever someone requests that thing, then I can check whether or not it has already expired, and if it has, then I can change that thing accordingly.

Why it wouldn't work: I'd also like to send an email out when that thing expires.

Thanks for any help!

Gyt Dau
  • 100
  • 8
  • 2
    Checking if the thing has expired upon request is the way to go. On the email part: You can set up a daily cron job, which would check, if anything expired within the last 24h, and if it did, then it would send an email, otherwise it wouldn't. Easy as that. – Tibor B. Dec 19 '14 at 11:02

5 Answers5

0

You can set up a cron job that runs a script which compares the date with the expriation date. If It is equal to the expiration date, send a mail, else do nothing.

bloomingsmilez
  • 411
  • 1
  • 6
  • 16
0

If you re on MYSQL you could use events. I ve used them successfully on expiring sessions.

Peter Chaula
  • 3,456
  • 2
  • 28
  • 32
0

You could choose to have kind of "runner" that checks for available jobs to run at the specific time and runs them. Then you can create a cronjob that fires the runner.

Luffi
  • 11
  • 5
0

Cron jobs are what you're looking for, you just have to find a way to run the task only once.

https://stackoverflow.com/a/5473841/2055152

Try this out to execute a command on 30th March 2011 at midnight:

0 0 30 3 ? 2011 /command

This answer offers a simple solution. If you want users to create their own events with PHP, just convert their desired date to the cron format. Just be careful on what you allow them to launch!

Community
  • 1
  • 1
0x5C91
  • 3,360
  • 3
  • 31
  • 46
0

You could save a time-stamp together with the user item, that you call expire for example

then you could run a cron job that removes all items that has passed the expired time.

if($item.expire < time())
{
   // Item has expired, remove it
}
JimboSlice
  • 692
  • 4
  • 13