Loop every 10 seconds

I run a php script via cron every minute, but there are parts inside the code that i would like to loop through so that it executes eg 6 times (so every 10 seconds: 0, 10, 20, 30, 40, 50)

I could use eg sleep(9), but i don’t know exactly each time how long the script will take. i would like it to be regulated at 10 second intervals.

Some sort of per-second timer? But i’m not sure how to build the loop and more importantly, the break or i’ll end up with endless loops!

Can’t you just loop through those parts of the code every x seconds?

But if you want to sleep for the remainder of ten seconds: (In the loop)

  • Get the current time. Add 10 seconds. (i)
  • Run the code.
  • Get the current time. Subtract that from (i). (ii)
  • Sleep for (ii)

Use the following command to give 10 seconds interval or so.