How I can send message at at a specific time in Telegram bots using PHP?

Viewed 219

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?

2 Answers

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

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

Related