PHP: How to start a cycle during a certain time of the day?

I have a loop that works in php ..

I want the loop to work only if the local (sydney, australia) time is between 13:00 and 15:00.

Can someone provide an example of how this will work? Thank!

+3
source share
3 answers

Placed

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

over the loop.

(Given that your web server is set to your local time.)

0
source

you can use cron if you want to authorize some scripts for some time ...

crontab -e

then add your script to execute as follows:

* * * * * /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)
+7
source
if (13 >= date('H') && date('H') <= 15)
{
 // your loop
}
0
source

Source: https://habr.com/ru/post/1776242/


All Articles