Alper
Alper

Reputation: 107

Execute script at variable time

I'm aware of cron jobs to execute commands at a certain time, but what if that time is not constant? For instance, suppose a user asks for a reminder email exactly 1hr after signing up for something, is there an easy way to go about doing this?

Timing is critical. I am actually trying to create AI that will essentially act on its own but only at variable points during the day. Any help would be appreciated!

Upvotes: 0

Views: 93

Answers (3)

David Laberge
David Laberge

Reputation: 16051

Here a workable flow:

  1. user Requests email in 1 hour
  2. You insert into the a table action (action_id, time)
  3. On the PHP server create a cron job to check the action in the action table every minute, then do the action that need to be done at that time

That is a simple example from the request. It might get a bit more complex then that.

EDIT : this suggestion might be good only if you need to be very precise with the time management!

Upvotes: 1

Baz1nga
Baz1nga

Reputation: 15579

if you dont wanna use the cron triggers and you are not comfortable with them here are two php scheduling libraries..

1) http://www.php.brickhost.com/

2) http://www.phpjobscheduler.co.uk/

Try them if you like:

Upvotes: 1

Marc B
Marc B

Reputation: 360672

You can use at to schedule jobs for specific times. cron is for repeating jobs, at is for one-shot/oddball interval ones. Both have a resolution of 1 minute, though, so you can't specify a start period with seconds granularity.

The command's available on both Unix/Linux and Windows.

Upvotes: 2

Related Questions