Welcome Guest, Not a member yet? Register   Sign In
Codeigniter CRON / CLI to run a controller issue
#1

[eluser]nevsie[/eluser]
Hi All,
I am trying to run a simple cron to do a simple task... however i seem to be having a bit of trouble - i think it is how the host is running its "scheduled tasks" as opposed to crons, but you might be able to advise...

I am simply running the following:
Code:
/usr/bin/php /home/sites/domain.com/public_html/index.php my_class my_function
and i have also tried:
Code:
/usr/bin/php /home/sites/domain.com/public_html/index.php "my_class my_function"
and various other tweaks...

But each time instead of running my function, it is always running the index function for that class - almost like it is ignoring the other variables.

Any thoughts on this?

EDIT // i do not think the variables are being picked up at all (i.e. my_class my_function) as after turning off defalt routing it fails altogether. guess it is a host issue unless others can advise?

Advice is appreciated. N
#2

[eluser]El Coder[/eluser]
Hey,

I ran into the same problem and I finally found a solution.

The reason lies in the config settings (in application/config/config.php):
Code:
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of 'AUTO' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'   Default - auto detects
| 'PATH_INFO'  Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI'  Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'AUTO';

While running your cron, CI does not detect the right URI in order to retrieve the right controller.

The solution:
http://phpstarter.net/2008/12/run-codeig...-line-ssh/

In short:
- build a bootstrap file
- define $_SERVER['QUERY_STRING'], $_SERVER['PATH_INFO'] and $_SERVER['REQUEST_URI']
- include CI index.php
#3

[eluser]El Coder[/eluser]
FYI:

Code:
$this->input->is_cli_request()

... is not working within this process.

I used a defined constant instead, as described (see link).
#4

[eluser]joanfihu[/eluser]
http://phpstarter.net/2008/12/run-codeig...-line-ssh/ This has saved me 2 or more hour. Thanks el Coder! Andele!
#5

[eluser]navotjer[/eluser]
In my case, everything was working as expected, except the:
Code:
$this->input->is_cli_request();

The trick was to fix the input class on line 311:
Code:
} else {
    if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
$this -> ip_address = $_SERVER['REMOTE_ADDR'];
}
}

Codeigniter 2.1.4

Best regards!
#6

[eluser]ivantcholakov[/eluser]
Hack 4. Running CodeIgniter from the Command Line, http://net.tutsplus.com/tutorials/php/6-...e-masters/




Theme © iAndrew 2016 - Forum software by © MyBB