In the specific case of the body of the question, @Sergio’s answer is the ideal solution.
I am posting this alternative only to future users who eventually need to repetitive tasks, but with little interval between iterations.
You can run a PHP script with a loop infinite at system startup, and have the intervals controlled by the function sleep()
, that frees the OS for other tasks:
<?php
set_time_limit( 0 ); // para o PHP poder rodar sem limite de tempo
while( true ) {
... aqui vai a sua função repetitiva,
que pode ser a checagem de uma condição
especial, um envio de email em horários
agendados, uma limpeza de DB, etc ...
sleep( 30 ); // numero de segundos entre um loop e outro
}
?>
This script must be executed at system startup, via script, unico scheduling or startup folders, depending on the OS.
Do not access this script from the browser! Use the command line not to unnecessarily occupy a web server process. Also, the directive max_execution_time
has default value 0
by the command line, allowing the loop rotate indefinitely.
best way I know is with cron Jobs even
– gmsantos