I have a php file that points to a url like so:
<?php
header('Content-Type: text/plain');
echo file_get_contents($_GET['url']);
The thing I would like my php file to do in addition to pointing to the URL is write a file to the server at a specific time each day -- let's say 6:00pm (18:00).
From my initial research, the write file part seems straight forward
file_put_contents('todaysDateData.txt', $_GET['url']);
However, figuring out how to call file_put_contents
each day at a specific time is throwing me for a loop.
Question: Is it possible to write a file in the manner described above at a specific time each day in native php? Ideally I would like to name the file with today's date and "Data" suffix (i.e. Mar-29-2018.txt).
Edit
Going from the suggestions below, I have researched cron
: I think the syntax for my use case is:
0 18 * * * path/to/my/command.sh
I think the date syntax is correct, but I'm still confused as to how cron
is used with my php file. Should I change the sh
file extension to php
since I'm using file_put_contents
? Or is this cron
date thing going in my php file itself and I have to make a .sh
(whatever that is?)