Reputation: 487
I have setup cron job, it is working properly, however when i directly runs the php file(from the path/url) it successfully runs, but from cron its not. However i set another very simple file to make sure my cron command/path is set correctly i created another file and used simple php mail function and its is running successfully. Kindly suggest me the possible areas to look into it. (I am using Cpanel)
Upvotes: 8
Views: 17666
Reputation: 3687
curl http://mydomain/auto_push/task.php?p=1
This is live working code from my project. See the image below:
Upvotes: 1
Reputation: 1188
I have faced the same problem. I am using task scheduling in laravel project on cpanel. My command was
/usr/local/bin/php /home/user_name/public_html/path/to/cron/script
It is a version issue. My server default php version is 7.1.33 but in my project the php version is 7.2. So, when i run the schedule command it takes the php7.1 which is not compatible with my projecct. So, according to cpanel documentaions the command is actually for different php version
/usr/local/bin/ea-php99 /home/shadhinapp/domain_path/path/to/cron/script
.
Any my cron job command is:
/usr/local/bin/ea-php72 /home/user_name/path_to_your_project/artisan schedule:run >> /dev/null 2>&1
Upvotes: 1
Reputation: 555
Instead of putting in cronjob command like
php -f /path_to_script/script.php
put command like this:
curl http://domain.com/yourscript.php
if you want to suppress output you can add > /dev/null
at the end.
So full command would be:
curl http://domain.com/yourscript.php > /dev/null
Hope this helps!
Upvotes: 16
Reputation: 1746
You shouldn't have any relative paths -- this includes both files and commands. For example, you shouldn't call just cp
if you want to copy a file, but something like /bin/cp
with the full path to the command. To find out the full path, you can run which <cmd>
at the command line.
Upvotes: 0
Reputation: 364
As alternative to cURL, you can call your script through text-based browser. Something like this:
lynx -dump http://localhost/script.php
Upvotes: 1