I have a function where you can check the status of orders with all orders that have status 1 and the last update was more than 5 days ago and will be canceled and send an email.
I thought about entering a page and that page starts to execute a loop, but shortly after closing the web page it stops running the function and stops making updates to the database, that is, it doesn't run anything.
this is my code:
$x = 0;
while ($x < 3) {
$x = $x + 1;
$dias1 = \Carbon\Carbon::today()->subDays(5);
$dias2 = \Carbon\Carbon::today()->subDays(15);
$encomendasnaopagas = encomendas::where('estado', 1)->where('updated_at', '<', $dias1)
->join('distritos', 'encomendas.distrito', '=', 'distritos.id')
->update(['estado' => 5]);
sleep(5);
**code to email *** //I don't put it because it's unnecessary code
$x = $x - 1;
}
it works, makes updates whenever I change the values in the database from 5 to 5 seconds but if you close the browser it stops, and I wanted it to be always running after starting it