I am looking for a way to run a PHP script between two set times (probably 5AM and 10PM), every 90 seconds. I was thinking of just making a bash script to move the file in/out of a directory at different times, but that would be messy and make all sorts of errors. Is there a better way to go about this?
Asked
Active
Viewed 7,170 times
3 Answers
8
To get a 90 seconds interval you could e.g. create two crontab
entries with an interval of 3 minutes and delay one of them by 90 seconds:
-*/3 5-22 * * * your_script.php
-*/3 5-22 * * * sleep 90;your_script.php

bmk
- 13,849
- 5
- 37
- 46
-
That sounds like a really decent solution. I will give it a shot tomorrow, thanks. Wouldn't a bach script that essentially did the same thing allow me to do one cron entry? `myscirpt.php sleep 90 myscript.php` along with a 3 minute cron entry? – tsz Jul 22 '11 at 06:46
-
1
Not sure if 90 seconds is possible, but here's 60
*/1 5,6,7,8,9,10 * * * root php your_script.php
And here's 120
*/2 5,6,7,8,9,10 * * * root php your_script.php
If you really really really need every 90 seconds, have cron run it every minute, put your entire php script in a "while ( $n < 2 )" loop, and sleep for 30 sec at the end of the loop.
Better yet, to keep your code and it's schedule apart, write a bash or PHP wrapper to call/include your script once, then again in 30 sec. Cron would call the wrapper every minute.

bioneuralnet
- 5,283
- 1
- 24
- 30
0
As from this link and modifying it for the time range
One as: "0 0/3 5-22 * * ?" to fire every third min
The second as: "30 1/2 5-22 * * ?" This will take care of the 90 second

Rahul P Nath
- 324
- 4
- 9