Cron jobs allow you to run scheduled tasks on your server, which can be really useful if you need to back up, clear or sort data on a regular basis. In this tutorial we're going to look at setting up a simple cron job via command line that will call a designated url each day.
Firstly you need to decide how frequently you want your job to run and then generate the correct text that we'll add to your cron table. You can use a crontab gode generator to do this or manually if you understand the simple configuration:
MINS HOURS DAYS MONTHS WEEKDAYS all tab delimited. So for example:
5 0 * * *
...will run at 5 minutes past midnight every day.
With this information, follow the steps below to add a cron job:
...and you're done. If you want to run a test, try changing it to every minute (all astrisks) and writing the update to a log, here's an example file to place in your public directory that the cron job would call (don't forget to create the cronLog.txt file first!):
$file = './cronLog.txt';
$current = file_get_contents($file);
$current .= "File updated at " . date('d-m-y h:i:s', time()) . " \n";