EllisLab text mark
Advanced Search
     
Cron job not execute method
Posted: 29 October 2012 01:36 PM   [ Ignore ]
Joined: 2008-07-19
9 posts

Hi,
I’m trying to run a method by cron job, follow command:

php $HOME/public_html/environments/dev/meetfun/index.php rotinas deletephototemp 

I received an email with the result of running and it presented the following problems:

Notice:  Undefined index:  HTTP_HOST…
Notice:  Undefined index:  SCRIPT_NAME ...
Message:  session_start()...

I tried to fix by changing the config.php to:

if (defined('STDIN')){
   
// You should hardcode the base url for cli, otherwise it will fails.
   
$config['base_url'"http://dev.ejsystem.com.br/meetfun/";
}else{
 $root 
"http://".$_SERVER['HTTP_HOST'];
 
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
 
$config['base_url'"$root";

But not work.
Beyond the errosr messages reported, it also brought me the default page and not the controller and methods passed, as if I had just run php $HOME/public_html/environments/dev/meetfun/index.php.

best regards.

 

 
Posted: 29 October 2012 01:51 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3800 posts

The session class relies on those $_SERVER variables being present and set as they are part of how CI tracks the sessions, which they won’t be set in a CLI request since it didn’t come from the web.

So you need to manually set $_SERVER[‘HTTP_HOST’] as well as SCRIPT_NAME (and if your custom code uses other hard-coded settings), preferably in your index.php if it’s a CLI request so the rest of the app will work.  It’s not enough to set the $config values.

 Signature 
 
Posted: 29 October 2012 02:22 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-07-19
9 posts

CroNiX thanks for the reply, I changed the variables $_SERVER and the errors stoped, but I have is that the controller $route[‘default_controller’], not that I passed: “routines / deletephototemp.”

php HOME public_html environments dev meetfun index.php routines deletephototemp 

That could be a problem in the version of php, server or version of CI?
CI Version: 2.1.2
PHP Version: 5.2.9

 
Posted: 29 October 2012 03:56 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3800 posts

IIRC, you might need to play with the $config[‘uri_protocol’] setting in config to get cron jobs working.  I don’t use the built in CI way for cron jobs so I’m not really sure.

I use a variation of this: https://github.com/EllisLab/CodeIgniter/wiki/Cron-job-bootstrapper

 Signature 
 
Posted: 30 October 2012 06:33 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2008-07-19
9 posts

Thanks a lot CroNiX,
I did work after see the “Cron Job bootstrapper” and the post blog http://phpstarter.net/2008/12/run-codeigniter-from-the-command-line-ssh/
Was perfect !