Do you think your script starts an endless loop with sleep to wait 5 minutes between iterations?
for (;;) { perform_actions(); sleep(300); }
Alternatively, you can have a file (e.g. is_running) and get an exclusive lock at the beginning of your script, which is released at the end. At least in this way you will not do anything destructive.
You can also combine these two solutions.
$fp = fopen("is_running", "r+"); /* is it already running? */ if (! flock($fp, LOCK_EX | LOCK_NB)) return; for (;;) { perform_actions(); sleep(300); }
And then the cron job is still running every 15 minutes. If the process is still running, it will simply fail, otherwise it will resume updating and resume updating every 5 minutes.
Brandon horsley
source share