Run Cronjob Codeigniter

How to run a method of a class in Codeigniter via CronJob?

Ex: principal.php accessed in http://www.meusite.com.br/principal/listaCron

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Principal extends CI_Controller {

  public function __construct()
  {
    parent::__construct();
    //Load Dependencies     
  }

  public function listaCron()
  {     
     file_put_contents("teste.txt", "Crontab executado em: ".date(‘d/m/Y H:i’));
  }

}
Author: Marcelo Diniz, 2014-10-21

2 answers

Follow manual link for this http://www.codeigniter.com/user_guide/general/cli.html .

In my location I left to run like this:

0 1 * * * php /var/www/meusite/index.php principal listaCron

But on the server I had to run by curl

0 1 * * * /usr/bin/curl -L --silent http://www.meusite.com.br/index.php/principal/listaCron
 1
Author: Marcelo Diniz, 2014-11-10 16:43:58

If your server supports curl, you can add this to the Crontab Command Line:

Curl http://www.meusite.com.br/principal/listaCron

 0
Author: Pedro, 2014-11-12 13:53:37