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 may need repetitive tasks, but with little interval between iterations.
You can run a PHP script with an infinite loop at system startup, and have the ranges controlled by the sleep()
function, which 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 should run at system startup, via script, unique scheduling or boot folders, depending on the OS.
Do not access this script through the browser! Do the command line not to unnecessarily occupy a web server process. In addition, the max_execution_time
directive defaults to 0
from the command line, allowing loop to run indefinitely.