Replace CRON

1

I made a script PHP which has to always run, usually 1 to 1 seconds or at most 2 to 2 seconds. The problem is that I set up multiple command lines on CRON to run every 1 second, but CRON automatically changes the configuration because I think it overloads the server.

My question is, would you like to put the script to run from X in X seconds without even having any users on the site. Would it have a way without using CRON?

    
asked by anonymous 05.04.2016 / 19:46

2 answers

0

The shortest range that cron accepts is one minute , ie you can not use cron to run processes with seconds of difference, directly.

However, what you can do is schedule a "trigger" program that runs for one minute, and that program fires another one within seconds.

A somewhat more stable solution is to make this "trigger" never stop, schedule the trigger to run at @reboot , and also schedule to run through the normal schedule, say, every 15 minutes. You must by some form of monitoring or lock to avoid running in parallel, but this solution ensures that the program " recover "if you do something wrong and unexpected.

The solution with infinite loop, without restart, would look something like this: In the cron tab:

@reboot "/caminho/do/script/disparador.sh" &

And the file disparador.sh something like this:

#!/bin/bash

while true; do curl "LINK"; sleep 2; done
    
05.04.2016 / 22:11
-1

The path is the same cron jobs.

Start rethinking if you really need it every 1 second or if you can change something in the code to be a bit more time-consuming, after all, there's no one on the site right now, a client-side ajax is acceptable, but cron tasks next to the server one at a second even overloads and many hosting does not even allow execution, usually the minimum is 1 minute.

    
05.04.2016 / 19:51