iCeR
iCeR

Reputation: 77

PHP: How do I run a loop during a certain time of the day?

I have a loop which runs in php..

I only want the loop to run if the local (sydney, australia) time is between 1pm and 3pm.

Can anyone provide an example of how this would function? Thank you!

Upvotes: 3

Views: 376

Answers (3)

user9440008
user9440008

Reputation: 582

if (13 >= date('H') && date('H') <= 15)
{
 // your loop
}

Upvotes: 0

mishunika
mishunika

Reputation: 1916

you can use cron if you want to autorun some scripts at some time...

crontab -e

then add your script to be executed as following:

* * * * * /path/to/script
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Upvotes: 6

AndreKR
AndreKR

Reputation: 33697

Put

if (date('H') == 13 || date('H') == 14)

above the loop.

(Given that your webserver is set to your local time.)

Upvotes: 0

Related Questions