1

Do you know crontab alternative that you can start,stop, pause,resume, reschedule via an API in PHP?

Or is this possible in crontab?

I have a long running php script that is executed by a cron. I would have to pause cron (while the script is executing) or reschedule so that it doesn't re-run my php script while it is still executing. After the script runs I would start the cron again.

Aivan Monceller
  • 4,636
  • 10
  • 42
  • 69
  • 2
    The issue of simultaneous running locks should be (and can be) solved in script itself, without editing schedule. – zerkms Jul 04 '11 at 08:46

2 Answers2

4

You might want to add the locking logic into your PHP script. E.g. the script might check for the presence of a lock file and abort if it is present. Otherwise it would create that file and delete it after it is done. You can add additional logic into your script for example checking the last time it was run and abort if it was last run less than 1 hour ago.

As for cron job, you can set up aggressive timings (say every 5 minutes) based on the assumption that the script is responsible for checking locks, last run time etc.

Salman A
  • 262,204
  • 82
  • 430
  • 521
  • " E.g. the script might check for the presence of a lock file and abort if it is present." --- I'd add that there is already `flock()` for locking purposes, which is condition-race-free solution. But for this issue even lock-file could be good solution. +1 – zerkms Jul 04 '11 at 08:57
1

You should try a job queue.

There are some implemented in pure PHP (Like the Zend Job Queue) or install a deamon service like beanstalkd (With a PHP-API like Pheanstalk.)

Christian Studer
  • 24,947
  • 6
  • 46
  • 71
  • I am already using gearman. I just have to run a php script (via cron) that checks the database for settings when tasks would be ran. Then the php script will send this job to gearman. My php script acts like a client to gearman. – Aivan Monceller Jul 04 '11 at 08:58