First time I’m trying to set a cron job on my website.
Before than that, I would like to try to run it in terminal.
In my cron jobs page I’ve found this command to run the script:
/usr/local/bin/php /home/functio1/public_html/path/to/cron/script
I’ve created a php file and I’ve changed the command above to point to the right directory.
The command apparently works as I don’t get any error, neither I don’t get any error file in the folder where the php file is located, but nothing happens.
This is the content of the php file:
<?php
include "../../../db/config.php";
include "../../../telegram/functions.php";
$query = "SELECT * FROM users WHERE DATE_FORMAT(user_birth_date,'%m-%d') = DATE_FORMAT(NOW(),'%m-%d')";
$result = mysqli_query($connection, $query);
while($row = mysqli_fetch_array($result)){
$dateOfBirth = $row["user_birth_date"];
$today = date("Y-m-d");
$diff = date_diff(date_create($dateOfBirth), date_create($today));
$age = $diff->format('%y');
$birthdays = "Oggi รจ il compleanno di: " . $row["user_name"] . " " . $row["user_surname"] . " (" . $age . " anni)";
sendMessage("max", $birthdays);
}
?>
I can say the code above works.
I’m using it at the moment by pressing a button on the website.
Basically it sends me messages on telegram for each user to help me to remember their birthdays.
I would like to be executed automatically once a day, but when I try to run the file using the command above nothing happens. What am I doing wrong?
Thanks for your help,
Max