1

I want to program a telegram bot (using PHP) that sends messages at a specific time. So if I did this :

$time = date('h:i a');

if($time == "12:00 pm"){
then send a message or audio or whatever is going to do }

The question is will the file on my host will test the if sentence every single sec? Isn't that will create pressure on the hosting & on the bot? Are there any other alternatives?

halfer
  • 19,824
  • 17
  • 99
  • 186
YK20
  • 11
  • 2

2 Answers2

2

You don't have to run the script every second; just set a cron job to run your script every minute. Look at this answer for more information:

Execute PHP script in cron job

WebPajooh
  • 442
  • 1
  • 3
  • 12
0

Do this:

$time = date('h:i a');
while(true){
    if($time != "00:00 am"){
        sleep(59);
    }else{
        ## CODE TO BE EXECUTED
        break;
    }
}

Sleep is a function used to stop the code for int seconds

M1001
  • 144
  • 1
  • 11