Why is cron hitting but not running my PHP code?
I have added a cron on my Linode server, and when I hit the same URL via my browser or using crontab extension it's working fine. However, when I added the cron on my Linode server via crontab, in the access log it's show me the URL is hitting but nothing is happen.
Can you please help me out?
4 Replies
It's possible this could be a permissions issue. Can you share what your crontab looks like?
The reason I ask is because if you're using wget
in your crontab, this will execute the command as the user who ran it. Since wget is handled by Apache, you'd need to edit the crontab for the Apache user www-data
:
sudo crontab -u www-data -e
The following Stack Overflow thread has some helpful tips for troubleshooting possible permissions issues:
https://stackoverflow.com/questions/7397469/why-is-crontab-not-executing-my-php-script
Yes we have added crontab like below
Login in ssh type below cmd
sudo crontab -e
Updated our required URL and save the file.
01 9 * * * curl http://[URL of SERVER]
5 * * * * curl http://[URL of SERVER]
10 * * * * curl http://[URL of SERVER]
01 0 * * 0 curl http://[URL of SERVER]
When I check the access log in apache then it shows the URL hit at the specific time PHP not working.
Please check.
As an infrastructure provider, the internal configuration of your Linode falls a bit outside the scope of our support. We don't have access to your system to be able to jump in and help out.
As mentioned in the article that @jardillo provided, there are many reasons why this may be occurring, such as a php command directly on the .php file that your URL is using:
php -f /var/www/html/result.php
Additionally, is there a reason you are curling your URL in crontab as opposed to calling the PHP file directly? I'd recommend giving that a shot and see if you have any different results.