• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Proper CLI / Cron solution?

#1
[eluser]Devon Lambert[/eluser]
Has anyone had success running Codeigniter from the Command Line. I am specifically interested in this functionality for use in a Cron setup, but I may have other uses in the future.

2 problems I've run into are errors being produced by the autoload functionality added to my config file and also errors produced by some of the constant variables that I have in my APP/config/constants.php file; The main two being SERVER_NAME and QUERY_STRING. I believe these errors are occurring because I am not running the code from the browser. That being said, I don't want to have to go through the entire site and re-factor code to make cron work correctly. There must be an easy, and secure, method for making this play nice with my current CI setup. It should be noted that I am using CI 2.0, although I suspect the solutions should work all the same.

Before you scold me, I have done some extensive searching over the past few days.

I have tried:
1) Codeigniter Wiki Post for making use of Cron
http://codeigniter.com/wiki/Category:Adv...ronScript/

and:
2) Codeigniter Cron Bootstrapper
http://codeigniter.com/wiki/Cron_job_bootstrapper/

and even this:
3) Phil's CLI Class
https://github.com/philsturgeon/codeigniter-cli

Has anyone used either of these two with success?

1) Cron Library
Checked this out, but it seems a bit unreliable, no?
http://ellislab.com/forums/viewthread/108154/P20/

2) Crontab Library
http://biozshock.blogspot.com/2010/03/co...brary.html

Thanks all.

#2
[eluser]n0xie[/eluser]
I use the Cron Bootstrapper without any problem on several servers.

If you want you could always just simulate the browser so you don't have to deal with running php running on the CLI using wget running from cron. That should do what you want without having to write or refactor any part of your site.

#3
[eluser]Devon Lambert[/eluser]
[quote author="n0xie" date="1295363539"]I use the Cron Bootstrapper without any problem on several servers.

If you want you could always just simulate the browser so you don't have to deal with running php running on the CLI using wget running from cron. That should do what you want without having to write or refactor any part of your site.[/quote]

Hey Noxie,

Unfortunately I am ruling out wget for the time being as I would prefer not to open another TCP/IP stack.

Do you have any constants that are defined and based around your environment? If so, how did they play with the Bootstrapper? I am using a similar setup to that used within Pyrocms and the variables are used throughout the site to determine if I am working in a dev environment vs a production environment.

#4
[eluser]n0xie[/eluser]
Yes I have a environment config item and an debug config item, but I don't see how those would affect a cronjob, unless you read them from the $_SERVER array. Since it's not a real HTTP request, it does not get filled so you have to fill the values yourself. See the Cron Bootstrapper code for reference.

#5
[eluser]Devon Lambert[/eluser]
Thanks again Noxie.

I did read them from the $_Server Variable. But I realized that I should fill them, so I made use of the --server argument provided by the bootstrapper.

This all seems to work now. :-)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.