cron after every 15 sec

Imran Naqvi picture Imran Naqvi · Sep 22, 2010 · Viewed 8.3k times · Source

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.

Answer

Lie Ryan picture Lie Ryan · Sep 22, 2010

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.