• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where to set CI_ENV for CI methods executed via cron?

#11
(04-11-2017, 10:57 PM)Diederik Wrote: Or you could just run wget with a url as a cron.


This answers is useful
Reply

#12
(04-11-2017, 08:28 AM)sneakyimp Wrote: Thank you for your response!

This does in fact address the problem but is not ideal for two reasons:
1) one must specify the environment every single time one specifies a cron/cli command. My crontab is going to have a dozen commands in it, all of which would need to have this value specified.
2) edits to the index.php file can make upgrading CodeIgniter more difficult because you have to propagate these changes manually merge these changes with any made by the CI core.

Is there not one place we can specify this value that works for both cron jobs and for cli execution?

1) Yes you would need to do that. You have to specify it somewhere unless you change the code I posted to always set a specific CI_ENV when running from CLI which will make testing difficult. If you use a staging server it's CRON jobs need a different environment than production so hard coding it for all command line calls is not ideal.

2) You aren't wrong, but copy and pasting a single if/else block isn't going to make upgrades difficult. The upgrade guide says when you need to replace index.php which happens very infrequently.

(04-11-2017, 10:57 PM)Diederik Wrote: Or you could just run wget with a url as a cron.

You can but then your CRON jobs are web accessible and if someone finds a link to them they can run them over and over again which could cause problems if they are designed to run at specific intervals.
Reply

#13
When you open your .bashrc file, note this comment near the very top of the script:

Quote:# If not running interactively, don't do anything

Crontab jobs are non-interactive, and your .bashrc halts there - that's why you don't get your environment variables.

If you really insist on using CI_ENV for this (there's nothing wrong with changing a line or two in index.php), just put your exports above that comment line.
Reply

#14
(04-13-2017, 02:53 AM)VTCAhmedabad Wrote:
(04-11-2017, 10:57 PM)Diederik Wrote: Or you could just run wget with a url as a cron.


This answers is useful

No, that answer is spreading bad practice.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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