0

I have a console programe that run only if current day is Sunday and set the target date(Completion date) for that programe next sunday.Now i want to make a programe that run once in a week and set the target date for that programe after 7 days.for example i programe run on Monday tthen target date should be next Monday if run on Tuesday then target date should be next Tuesday and so on.

$sunday = Date("D");   
      if($sunday == 'Sun') {
          remaining function
      }

I have this logic for my first programe.I am using this programe in CakePhp Console(Shell).Any help for second one?

Thanks

Moaz Ateeq
  • 397
  • 1
  • 11
  • 23

1 Answers1

1

Use the at command. It is the little know cousin of cron. It allows you to execute a command once at a specified date and time, which can be years from now.

From your description I gather you want to execute a script at any time you want, then execute it again after 7 days. This means your PHP script will have to schedule itself to run again. at can take an absolute time or an increment:

at -f /bin/ls now +7 days

Will try to output a directory listing 7 days from now (which will probably end up in /dev/null, but that's a different matter). You should replace /bin/ls with the full path of your PHP script, and execute the at command from a system() call (it is not part of PHP itself). It's a bit convoluted, but you can be guaranteed the script will be executed, even after a reboot. Of course, the script will then reschedule itself again, unless you take countermeasures...

When the script is run in 7 days, its output will not be visible so make you sure you either redirect the output or write it to a log.

JvO
  • 3,036
  • 2
  • 17
  • 32