0

How do I run some php function in controller every 1 hour using cPanel Cron Jobs?

Note: for testing reasons, I decided to execute this function every 1 minute.

Example:

class Mycontroller extends CI_Controller {

     public function index() {
         //something
     }

     /* HERE IS IT*/
     function clear_ip_address_list_every_one_hour(){

         $data['ip_adress] = '0'; // set to 0
         $this->my_model->model_function_to_action($data);
     } 
} // end of class

I want clear_ip_address_list_every_one_hour() to execute every one minute.

CDspace
  • 2,639
  • 18
  • 30
  • 36
Kamarul Anuar
  • 312
  • 4
  • 16

1 Answers1

0

You can setup a cron job like:

 Minute Hour Day Month Weekday Command
      *   *   *     *   *      curl https://yourDomain/mycontroller/clear_ip_address_list_every_‌​one_hour 

If you have a custom route to your method, you need to use that.

But usually, CodeIgniter does uses /controllerName/controllerMethod urls

In some edge-cases, you would need to replace curl with the full path to the curl executable.


You need to be careful with this frequency. I can imagine there's something really wrong with your application logic if you need to do something "every minute". Also, some hosting providers might not be happy with a "once-per-minute" cron job and might cancel it for you.

Alex Tartan
  • 6,736
  • 10
  • 34
  • 45