I want a script to run randomly between 30seconds to 1minute during the day between between 8am to 8pm.
Is there anything stopping me from just opening a PHP script one time with a 30-60sec sleep in a loop? And then it checks whether the time is between the 8am and 8pm?
What is the disadvantage to doing this compared to a Cron job? Can a Cron job run at random times?
You can implement such a long lasting scheme in php. It works (provided you use php from the command line…). The only thing that might be a minor disadvantage is that there is no recovery in case of a failure. This would be different when using a cron job: a new process would simply be started. However this obviously introduces other risks, so there is no ‘better’ way.
Cron cannot start processes at random times. however you can start your process at fixed intervals and use an initial sleep command of random length. That should have the same effect.