Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

CLI interface not functioning under cron #984

Closed
AndreiBarsan opened this Issue Jan 26, 2012 · 12 comments

Comments

Projects
None yet
6 participants

Hello, I am using CodeIgniter for a rather large commercial application, and I need to run an hourly cron to manage sending some mail. Pretty basic. I was using the bootstrapper posted on the wiki - http://codeigniter.com/wiki/Cron_job_bootstrapper, with the following cron command:

/home/xxx/cron/cronBS.php --run=/admin/cron

Worked like a charm. Now, I updated to the latest version of CodeIgniter, 2.1.0 and while browsing the documentation, I noticed that the bootstrap script was useless since it seemed to work easier, http://codeigniter.com/user_guide/general/cli.html by just calling

php /home/xxx/www/index.php admin cron

However, this does not work. When printing the output in my email, it just shows the HTML of the landing page, with no error message being displayed. I know it's not some sort of botched session code, since switching back to the old version works great and the proper log files are created by the script.

What's strange is that running this via the CLI through SSH works, and if I remove the security functionality, so does simply accessing site.com/admin/cron, which is strange.

I cannot put my finger on it - could it be a true CI bug, or a problem with crond?

Another notice - running it as
/usr/bin/php "/home/xxx/www/index.php" admin cron
produces the same result as when the script is ran by the cron daemon. Odd.

Contributor

Mancy commented Feb 28, 2012

I can't get the CLI to work from ssh console, although the method does work from the URI

I'm executing the command using root user
/usr/bin/php -f /file/path/to/project/index.php controller method
but accessing the URI: http://localhost/controller/method does work

no error what so ever seen in logs or httpd log or mysql , the test method has very easy email() test function

if i managed to do syntax error into the method, i'll get PHP Parse error printed into the ssh console.

I don't know actually what is the reason.

Contributor

narfbg commented Feb 28, 2012

Is that with 2.1 (works for me) or the current development code?

Contributor

Mancy commented Feb 28, 2012

yes that does happen with CI 2.1.0

I'll create new empty project and check out of my current application, if it works then i must have something in my application that prevents it from working from CLI, although it works pretty well from URI and that is the strange part.

Contributor

narfbg commented Feb 28, 2012

Just a guess, but - it's most likely to happen if you've extended the core Controller class.
Another possibility is the Session library - if it's that, it's still a bug.

Contributor

Mancy commented Feb 28, 2012

I have created empty project and the same test controller worked from CLI.
by the way, I'm not extending the core controller class, I'll keep investigate about the issue and update here.

Contributor

Mancy commented Feb 28, 2012

I was having issue with my code, it's not Codeigniter to blame, sorry .. now it works

Contributor

narfbg commented Feb 28, 2012

OK ... @AndreiBarsan Can you check again as well?

I'm going through a very busy schedule right now, I'll post some more tests as soon as I can.

Contributor

philsturgeon commented Apr 26, 2012

Did you have a chance to run those tests?

@narfbg narfbg closed this Oct 5, 2012

Contributor

jwensley2 commented Jul 17, 2013

I've had this problem on a server running CentOS + cPanel.

In the command line I can use
php /path/to/index.php controller method
but in a cron I need to use
/usr/local/bin/php /path/to/index.php controller method

I don't know enough to know why it works like that, but maybe this will help someone else who has the same problem.

Because you don't have PHP directory in Linux $PATH variable so you can use it like that

php /path/to/index.php

use this command to look if there are exists "/usr/local/bin" path

echo $PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment