2

I need to execute a function every tot hours, right now I'm doing it manually by going to:

http://www.mywebsite.com/controller/function

is there a way to schedule the execution of this function every four hours for example?

7
  • Yep, use a cron job on *nix, or the scheduler on Windows. What platform are you on? Personally I'd move this out of the web tree and run it on the CLI, unless it really must be run in a web environment. Commented May 15, 2012 at 10:10
  • Thanks for your answer. I'm using Debian Linux. Commented May 15, 2012 at 10:44
  • Right, use cron then - if you do a web search for 'cron php' there are loads of resources for that. Works on shared accounts too, usually. And as I say, this shouldn't be in the web tree - run it on the CLI, so it will look something like /usr/local/php /my/path/outside/the/web/tree.php <param>. Commented May 15, 2012 at 10:51
  • you're right, right now the function can be executed by everyone... Commented May 15, 2012 at 10:54
  • @halfer just another question: inside the .php file that contains the code will I be able to get a CodeIgniter instance doing this "$CI = &get_instance ();" ? Commented May 15, 2012 at 11:01

1 Answer 1

3

In the best case you should set cron jobs to request that URL every hour using wget or CURL in the *NIX command line:

0 1 * * * wget http://www.mywebsite.com/controller/function

As this URL is accessible publicly secure it with a parameter like http://www.mywebsite.com/controller/function?key=my_secret_key_here

Also take a look at this online service: http://cronless.com/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.