Welcome Guest, Not a member yet? Register   Sign In
Cron outside application folder
#1

[eluser]Unknown[/eluser]
Hello guys,

Here is my CI app:

/MYFOLDER
- application/
- system/
- css/
- cronjobs/
- ....
- index.php

I want to create a controller that does some stuff and put it in cronjobs folder, so if I upload a new version of application folfer, it does not affect to the cronjobs functions.

How can I create a controller in that folder so that I can run it using cron?

Thank you!
#2

[eluser]NotDior[/eluser]
Read up on the CLI stuff: http://ellislab.com/codeigniter/user-gui...l/cli.html

It's just like if you were calling a controller however you'll be calling it from the command line.

Your best bet in your scenario is to keep it in your controllers (don't believe there's a way to move your controllers outside of that folder), but make it only callable by the CLI.

If your server runs with cPanel, you'll need to call php a bit differently.
#3

[eluser]PhilTem[/eluser]
[quote author="NotDior" date="1347547190"]Read up on the CLI stuff: http://ellislab.com/codeigniter/user-gui...l/cli.html

It's just like if you were calling a controller however you'll be calling it from the command line.
[/quote]

I guess that was not what the OP was referring to. What he wants to do is put a controller inside ./cronjobs rather than in ./application/controllers which is however not feasible without creating your own MY_Loader to locate the file.

It's easiest - if you're just starting with CI - to put you cron-controller inside ./application/controllers and create it as if it was a standard controller except that you will be performing your cron-tasks Wink
#4

[eluser]NotDior[/eluser]
Phil - I'm curious to know more about the MY_Loader stuff that your talking about. Do you have a link or a post somewhere that talks about that?
#5

[eluser]CroNiX[/eluser]
MY_Loader would just be an extension to the loader class, adding a method to load a controller from a directory other than the hard-coded /application-dir/controllers dir.

See the user guide on Extending Core Classes

However, just a simple cron controller in the regular controllers dir as Phil suggested with a check to make sure it's being executed from the CLI and not from a web request would be easiest.
#6

[eluser]NotDior[/eluser]
CroNiX - Thanks for the link. I'll give it a read! I still think the regular controller with CLI limitation is the easiest and best way to go. That way a new person isn't hunting all over the place for them.
#7

[eluser]Unknown[/eluser]
Finally I think I'll put the cronjobs inside the application folder and I'll check the way the script i being called using is_cli_request so those controllers are not available using the browser.

Thank you for all the responses!




Theme © iAndrew 2016 - Forum software by © MyBB