Reputation: 10625
After several different attempts I've created a cron task which runs the following file every minute - this file is called cron.php:
<?php
echo file_get_contents('http://website.com/search/all');
?>
search is my controller, all is my function.
When accessing this file through terminal like so, the file works correctly and expected:
php /srv/users/serverpilot/apps/websitename/public/cron.php
However, as soon as I schedule it inside crontab -e it doesn't run correctly (if at all) and doesn't show any errors. This is the contents of crontab -e:
* * * * * php /srv/users/serverpilot/apps/brickmulesite/public/cron.php
When I look through my cron log (grep cron /var/log/syslog) this is what I see:
Jan 27 13:55:01 websitename CRON[22231]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 13:56:01 websitename CRON[22237]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 13:57:01 websitename CRON[22241]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 13:58:01 websitename CRON[22247]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 13:59:01 websitename CRON[22260]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 14:00:01 websitename CRON[22266]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 14:01:01 websitename CRON[22270]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 14:02:01 websitename CRON[22274]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 14:03:02 websitename CRON[22278]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 14:04:01 websitename CRON[22363]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 14:05:01 websitename CRON[22367]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 14:06:01 websitename CRON[22372]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 14:07:01 websitename CRON[22376]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
Jan 27 14:08:01 websitename CRON[22383]: (root) CMD (php /srv/users/serverpilot/apps/websitename/public/cron.php)
It appears the cron is running but isn't running the code in the file. What am I missing?
I know I should be able to run it using the following but that didn't work either so I wanted to simplify the issue:
php -f /srv/users/serverpilot/apps/websitename/public/index.php search all
Upvotes: 0
Views: 385
Reputation: 116
simply use this with curl
curl "http://www.nameofdomain.com/controllername/functionname"
in Command textbox
Upvotes: 0
Reputation: 10625
[SOLVED]
You'll notice I'm using ServerPilot as part of my website. Their platform allows me to choose which version of php my web app should run. Anyway...
The fix was found on this website: https://serverpilot.io/community/articles/how-to-use-the-php-cli.html
What I needed to do was change the PHP call inside the cron so that it read:
* * * * * php5.6-sp /srv/users/serverpilot/apps/websitename/public/cron.php
Note the php5.6-sp
I imagine this is very specific to ServerPilot users.
Upvotes: 1