php - How to schedule notification

So I have a database that I query from to check if the date on there is equals to today's date. Is there a way I can run this PHP script without visiting this page to check if there is any date that is equals to the todays date and send FCM notification? Below is example of what am looking at:
<?php
$todaydate = date("Y-m-d");
$query = "select * from TABLE where date = $todaydate";
$result = mysqli_query($db, $query);
if(mysqli_num_rows($result) > 0){
...sending FCM notification
}
?>
I know cronjob can do this but don't know how to use on to achieve this.
Answer
Solution:
You can just run the script (for example) every 12 hours.
You can either do this with the Linux commandcrontab -e
for the currently logged-in user or you can edit/etc/crontab
to run the script as a specific user.
Withcrontab -e
your line would look like this:
0 */12 * * * php /path/to/script.php >/dev/null 2>&1
As I said, in/etc/crontab
you can specify a specific user. It would look like this:
0 */12 * * * username php /path/to/script.php >/dev/null 2>&1
username
can be something like www-data. Just make sure the specified user has read/execute permissions on the script's file.
>/dev/null 2>&1
means that the output of the command is muted. You could also write the output into a file. There are also crontab-generators.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: php_network_getaddresses: getaddrinfo failed: temporary failure in name resolution
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.