Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cron after every 15 sec

I cannot set cron time to less than 1 minute even on my dedicated server. I need it to run every 15 seconds because it calls betfair api and calculations are highly time dependent. Please advise.

like image 697
Imran Naqvi Avatar asked Dec 02 '22 04:12

Imran Naqvi


2 Answers

If you need to call a job every 15 second, don't use cron. cron is designed for requesting jobs to be done much later.

Instead, after the parent finishes the job, sleep for 15 seconds then call the child script, then exits. The child script can do its job, sleep for 15 second then call the next script. Lather, Rinse, Repeat.

If your server doesn't have time limit, then you don't even need to spawn a child script. Just sleep ever 15 seconds, do your thing, sleep 15 second, do the next thing, and so on. A sleeping script doesn't consume CPU, though it do consume RAM. But that's better than cycling your host's PID; which might cause your host to go uneasy.

like image 78
Lie Ryan Avatar answered Dec 03 '22 18:12

Lie Ryan


Cron only lets you run things as fast as once a minute.

What I would do is do the 15 second timings inside your script.

  • Execute a parent script once a minute.
  • Execute children scripts every 15 seconds within that script before it exists and a new cycle begins.
like image 23
thomasmalt Avatar answered Dec 03 '22 18:12

thomasmalt