Welcome Guest, Not a member yet? Register   Sign In
Calling Controller with Cron Job
#1

[eluser]bazianm[/eluser]
Hi,

I have to run a procedure once a day to send out emails to subscribed users. The application is written using CodeIgniter. Since this is a timed event, I was thinking I need to use a cron job to do it.

I have done some research and it seems like the general advice is to use wget in the cron job with a URL calling the job.

My questions: The application has security and I want to ensure that only the cron job can call the controller, not a user with a browser. Any ideas how I can accomplish this? Or, is there a better way to approach this in general?

Thanks in advance.
#2

[eluser]jesterhead[/eluser]
You can use wget and curl in your cron job to access your Controllers, by calling the right url.
Code:
0 0 * * * /usr/bin/curl https://yourwebsite/controller/function/param
0 0 * * * /usr/bin/wget https://yourwebsite/controller/function/param

I don't know if this is secure enough, but you can set it so only your server can call your controller by including this in your constructor:
Code:
function __construct(){
parent::__construct();

if($this->input->ip_address()!='your.server.ip'){
  header('HTTP/1.1 404 Not Found');
  die;
}
}
#3

[eluser]CroNiX[/eluser]
Code:
if ( ! $this->input->is_cli_request())
{
  die('request was called from url');
}
#4

[eluser]CroNiX[/eluser]
And check out the manual for using CI in the CLI environment - you don't have to use wget.




Theme © iAndrew 2016 - Forum software by © MyBB