Something setInterval style for PHP

Asked

Viewed 156 times

0

Is there a function in PHP that schedules a certain routine? What I would like is to turn the day, in case, 00:00, a script, in php, was fired to perform a certain task. It would be more or less the javascript setInterval, where each time something is executed. In my example, I always want that when changing the day, the script is executed searching some information in the bank and changing this information according to the previously established need.

1 answer

1


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

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

In the , 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();

The Laravel uses the library cron-Expression as a basis.

  • Thank you very much, Valdeir.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.