I have a very simple PHP script that is supposed to make a POST request. The code is the following:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
mail('myemail@gmail.com','Script run with success','Script run with success',$headers);
When I execute it from the browser, it works fine. However, when I try to execute it as a cron job the Curl part won't work. The rest of the script works even as a cron job, as I receive the confirmation email at the end.
Here's the cron entry:
*/5 * * * * /usr/bin/php /home/username/scripts/test.php
Any clue regarding why Curl is not executing as a cron job?
Update: I tried to run the script via shell and the Curl part failed to run too. So:
- Browser: curl works
- Shell: curl doesn't work
- Cron: curl doesn't work
Update 2: Adding -dsafe_mode=Off while running via shell make the script run fine. However adding the same flag to the cron entry didn't do anything. So I still need to figure out how to make it work from cron.