Welcome Guest, Not a member yet? Register   Sign In
Cron Job and CLI
#1

I have setup a cron job and call it like this:

php /home/sitename/public_html/www/index.php controllername method

If I connect to my server using SSH (putty) and call this command, everything runs just fine.

But when my account cron job runs (using same command) I receive an email from my server displaying the HTML from my home page. 

It appears it is ignoring the controller and method calls. 

CI_VERSION = '3.1.9';
My server is CentOS 6 WHM CP.

Any ideas what is happening?
Reply
#2

Try putting the command in a shell script and running that.
Reply
#3

(02-04-2020, 12:08 PM)Goddard Wrote: Try putting the command in a shell script and running that.

Same results running in shell script -- grabbed the index page and ignored controller and method.

However, I did find the answer -


I had to be more specific about the PHP version I was running:

Code:
/opt/cpanel/ea-php71/root/usr/bin/php /home/accountname/public_html/www/index.php controller method

I have no idea why this would make a difference, but it does work now. I do not have to use full path PHP calls for other cron jobs (that don't include controller and method) I just call:

Code:
/usr/bin/php /home/accountname/public_html/www/filename.php
Reply
#4

(02-05-2020, 08:03 AM)Roddyguy Wrote: I have no idea why this would make a difference, but it does work now.

Some OS distributions use a different php.ini for the CLI than is used for Apache (or other httpd). Perhaps that ini is pointing to a different version of PHP?
Reply
#5

(02-05-2020, 09:23 AM)dave friend Wrote:
(02-05-2020, 08:03 AM)Roddyguy Wrote: I have no idea why this would make a difference, but it does work now.

Some OS distributions use a different php.ini for the CLI than is used for Apache (or other httpd). Perhaps that ini is pointing to a different version of PHP?
Thanks Dave. Makes sense.
Reply
#6

Hey there!
Thank you for posting this. I was pulling my hair out because I couldn't pass the controller and the method in the cron job...
I confirm that by using the full path to the php compiler - in my case /usr/local/bin/php - it worked.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB