S
S
saniii2019-07-27 06:58:29
Task Schedulers
saniii, 2019-07-27 06:58:29

Does cron run a task if it is already running?

There is a script written in php, the cron is set to run every 30 minutes, the question is, Will the cron script run if the previous one has not yet completed its work?
It is difficult to calculate the operating time, since it can work for 5 minutes, it can also work for several hours.
And how can you avoid restarting, if they exist (preferably by regular means of the system)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-07-27
@Compolomus

Create a lock file before starting it, delete it when the task is completed. At the beginning of the script, check for a lock file
Links
https://www.php.net/manual/ru/function.touch.php
https://www.php.net/manual/ru/function.unlink.php
https:/ /www.php.net/manual/ru/function.file-exists.php
Sample script

const LOCK = 'lock';
if (!file_exists(LOCK)) {
touch(LOCK);
// тут код скрипта который запускается по крон
unlink(LOCK);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question