skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search