I have a PHP file that is deployed in a server:
/var/www/html/cron/leave_mail.php
The code inside this PHP file is just sending a request via CURL (The server of the url is the same server of the cron job):
<?php
$url = "http://my-site.build.com/sendmail/sendmail_leave";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$head = curl_exec($ch);
curl_close($ch);
?>
Now I created a cron job on the same server where I deployed the PHP file:
* * * * * php /var/www/html/cron/leave_mail.php
After 1 minute, it didn't execute the command inside the PHP file, however, I can see on the system logs that the cron job runs.
I run my local virtual machine with ubuntu os and created the same cron job, executing the same file. After 1 min, I can see that it executes the command inside the PHP file because the data on the database was updated.
I'm really puzzled on why the cron job on the server didn't executes the PHP command. I'm stuck on this issue.
question from:
https://stackoverflow.com/questions/65891092/sending-http-request-through-cron-job 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…