Welcome Guest, Not a member yet? Register   Sign In
How to use codeigniter via command line or cron job?
#1

[eluser]sneakyimp[/eluser]
I'm hoping someone can tell me the best way to run a codeigniter controller method from the command line or as a cron job? I'm about to rebuild a big website and there are at least a couple of cron jobs that must run. Given that I'm building all my logic and classes assuming a CodeIgniter context, I'm wondering how to construct a php script or crontab command that can simply call a controller's method.

Is this even possible?

Simply trying to run index.php via the command line results in a lot of HTML output that includes one error:
Code:
Severity: Notice
Message:  Undefined index: REMOTE_ADDR
Filename: core/Input.php
Line Number: 351

This tends to make me think that CodeIgniter is not designed to support this kind of action.

If CodeIgniter does support this kind of action, how does one specify controller and method?
#2

[eluser]InsiteFX[/eluser]
CI Search Cron Jobs
#3

[eluser]CroNiX[/eluser]
Which version of CI are you using? More recent versions allow this: http://ellislab.com/codeigniter/user-gui...l/cli.html

@InsiteFX you can't post a link to search results. It creates a unique id to the results which expire.
#4

[eluser]sneakyimp[/eluser]
Yes that link to the documentation looks great! You can apparently supply the controller name, method, and params via CLI. Great!

Although I still wonder if you'll get the error about the undefined array index? Will try it shortly.
#5

[eluser]CroNiX[/eluser]
If you still get that error, are you using sessions by chance? Or using $this->input->ip_address()? If so, those both use $_SERVER['REMOTE_ADDR'] which doesn't exist when using the CLI. You can check out this for a possible fix: https://github.com/EllisLab/CodeIgniter/issues/1890
#6

[eluser]Unknown[/eluser]
The PHP REMOTE_ADDR error while using CLI occurs because in your config/autoload.php libraries you have most likely added "session".

The possible fix posted by CroNiX above fixed this issue for my CI install allowing me to leave session autoloaded.




Theme © iAndrew 2016 - Forum software by © MyBB