0

I want to create and use cron job . But i want it to be done by my script in codeigniter. So is it possible to add a cronjob for a perticualr time when my conrtoller function is completed ?

If so please help... Thank you

2 Answers2

2

Sure you can!

You can execute any controller/action in codeigniter on command line this way:

php index.php controller_name action_name

So you can point a cron job on this particular route and execute anything that don't depends on browser (like sessions/cookies) into your job.

More info: http://www.codeigniter.com/user_guide/general/cli.html

Sparky
  • 94,381
  • 25
  • 183
  • 265
taiar
  • 542
  • 7
  • 21
  • Yes, you can since the user that executes de application (it would depend of your webserver's configuration) has the right permission to create a cron that'll exec the script. – taiar Aug 12 '14 at 15:46
  • i am trying also the same thing...but through crontab -e command i am not able to create new cron job – Rishi Shrivastava Aug 13 '14 at 06:17
  • This was answered here: http://stackoverflow.com/questions/4421020/use-php-to-create-edit-and-delete-crontab-jobs/ – taiar Aug 13 '14 at 13:25
  • I see you're new to SO. If you feel an answer solved the problem, please mark it as 'accepted' by clicking the green check mark like this: http://i.stack.imgur.com/QpogP.png Thanks! – taiar Aug 13 '14 at 13:30
  • This isn't working for me ... that format takes it to the index page but not to the controller and method. Any idea what the problem might be? – Rob Fenwick Oct 08 '14 at 00:02
0

You can use curl in cron jobs to execute or run the codeigniter in cron jobs

* * * * * /usr/bin/curl https://www.domain.com/controller/function
Sandeep
  • 1,474
  • 6
  • 20
  • 32