Welcome Guest, Not a member yet? Register   Sign In
proper place to insert code
#1

[eluser]Marc Arbour[/eluser]
Dear CI community.

I need help with the fact I have a small learning disability that prevents me from going through the user_guide or reading extensively on forums. I get confused too quickly and tend never to find my answer. But I am not stupid since I have created 2 cool websites with the help of CodeIgniter.

I just need to be pointed in the right direction. That's all.

What I need as an answer: I need for you just to tell me, as examples,
1- this should go in a class that should work this way
2- this should go in a helper that should be loaded in such a maner
3- anything that tells me how and what... I'll manage with reading/learning alone afterwards.

What is, in your opinion, the best place to insert code to be executed "once a day"? (or, if need be, more often but not at every page view)

Explanations: Once a day I need to delete specific records from a table in a database. I would like this to be cron independant in case we move the website to another server.

Requirements: It needs to be in a place where database connection is already done since it's one single line as this one:
Code:
$query = $this->db->query('delete some records where condition is met');

Limitations: I tried putting in controllers initialization in some "more popular" controller, but the downfall is that I need to put it almost everywhere to garantee it's executed at least once daily when only once should be sufficient. Thus freeing server resources.

Thanks for helping out.

Marc.
#2

[eluser]sophistry[/eluser]
you are overcomplicating it for the wrong reason.

i strongly suggest that you just create a new controller and call it (via curl or wget) using cron once-per-day (your stated requirement). it sounds like you know how to use cron to call web pages...

it seems like trading a little problem for a big one to call a function at every page request just to make sure it runs once-a-day...

if/when you move the website to another server, just update the cron job.
#3

[eluser]Zack Kitzmiller[/eluser]
I have a PHP file that lives outside of codeigniter. It has various routines in it in that are all executed via cron. (update statement balances, delete inactive users, etc).

I completely agree with sophistry. You're completely over complicating this.




Theme © iAndrew 2016 - Forum software by © MyBB