Something setInterval style for PHP [duplicate]

0

Is there a function in PHP that schedules a given routine? What I would like is that at the turn of the day, in the case, 00:00, a script, in php, would be triggered to perform certain task. It would be more or less the setInterval of javascript, where every time something is executed. In my example, I want you to always change the day when the script is executed by searching for some information in the database and changing that information according to the previously established need.

    
asked by anonymous 18.01.2018 / 08:00

1 answer

1

Unlike a code in Js , the code in PHP "dies" after the request. That is, it is not possible / feasible to do something like setTimeout or setInterval .

The best solution for these cases is to use a Unix task scheduler, use crontab .

No , you can use the library Schedule and CallbackEvent to help you with scheduling scripts.

Ex:

/* Agendar para executar o script a meia-noite. */
Schedule::call(function() {
    /* Code Here */
})->daily();
  

Laravel uses the cron-expression library as a base.

    
18.01.2018 / 08:51