-2

I have a php script that i need to run every 4 seconds for one hour a day, what is the best way to do this. I look up a way of using cron and sleep and also watch but what would be the best way of doing this over all?

Watch

watch -n10 command args

cron:

* * * * * /foo/bar/your_script
* * * * * sleep 4; /foo/bar/your_script
* * * * * sleep 8; /foo/bar/your_script
* * * * * sleep 12; /foo/bar/your_script
Sean
  • 1
  • 1

1 Answers1

0

In short, it seems there isn't a simple way to do this using cron, since cron has a granularity of 60 seconds. Basically you would have to find a workaround.

One workaround, that you seem to have already come across, is to have multiple events with offset start times. E.g. Running a cron every 30 seconds

Another is to do more granular scheduling within the PHP script itself. E.g. In this answer

At that point it might make sense to then also make your PHP script a daemon process: Run php script as daemon process

ChrisM
  • 1,565
  • 14
  • 24