user3392106
user3392106

Reputation: 39

Perpetual cron job

I have developed a php script, that I want to run continuously.

For example, the script run.php executes a list of tasks, but I don't know how long it will take: it can take 30 sec, 1 min, 2 min, or more.

The problem is this script can't be executed simultaneous.

So I can't use the cron job because if I setup a cron job every minute, but the script is running during more than 1 minutes, I'll have bugs).

In fact, I want that this cron job to be Perpetual executed : everytime run.php is ended, the script run.php is reloaded, again and again...

I don't know how to resolve this problem.

Any help please ?

Thank you.

Upvotes: 0

Views: 210

Answers (1)

pah
pah

Reputation: 4778

You've [at least] two options:

  • Under run.php code, determine if it is already running (by setting some external control system that is checked at the beginning of the script) and setup the crontab job as you described. [I recommend this approach].

  • Use something like (while :; do php run.php; done) & run it once, and put it inside the /etc/rc.local to make it run at every system start. I don't really like this approach, but it's a possible solution.

Upvotes: 1

Related Questions