I want to run some functions that do things like change statuses of records and deleting expired records in a database in my CakePHP. E.g. every 24 hours.
The obvious issue is running a function requires to my knowledge that someone actually access the website. Is it possible to run a function automatically with no user accessing the website to get the code to run?
So for example I have the following code:
function garbage()
{
$deadline = date('Y-m-d H:i:s', time() - (24 * 60 * 60)); // keep tickets for 24h.
$ticketObj = new Ticket();
$data = $ticketObj->query('DELETE from tickets WHERE created < \''.$deadline.'\'');
}
This deletes expired tickets that are over 24 hours old. But this runs ONLY when someone is accessing the website. Could it run every night at midnight automatically?