简体   繁体   中英

how to run cron in cpanel using codeigniter

how to run cron in cpanel using codeigniter

<?php

class Cron extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

    $this->load->model('email_model');

    }

    public function index()
    {

        $c_date = date('Y-m-d');
        $remider_data   = $this->email_model->get_customer_remider_data(array('status'=>'1', 'reminder_date_before' => $c_date));
        foreach($remider_data as $remider_data_mail)
        {
                    $mailTo  = $remider_data_mail->reminder_email;
                    $nameTo = $remider_data_mail->reminder_email;

                    $mailFrom  ="test@gmail.com";
                    $nameFrom  = "project Board";

                    $subject  ="reminder_date_before";
                    $body     =  $remider_data_mail->reminder_description;          

                $headers = "Content-type: text/html;\n";
                $headers .= "From: ". $nameFrom . " <" . $mailFrom . ">\n";                
                $headers .= "Reply-To: ". 'no-reply@gmail.com' . " <" . 'Project Board' . ">\n";
                $headers .= "Return-Path: " . $mailFrom ."\n";

                    if(mail($mailTo, $subject, $body, $headers))
                    {
                        echo 'email sent';
                    }
        }


    }

}

It is my controllers-> Cron file.

I'm using index function to using Cron job.

and I set in cpanel /usr/bin/php /home/*****/public_html/*****/index.php cron index

and also I using php /full-path-to-cron-file/cron.php /test/index

You can call codeigniter from command line with:

php /var/www/ci_folder/index.php controller_name function_name

Reference here: https://www.codeigniter.com/userguide3/general/cli.html

I don't know why,

php /path/to/the/project/index.php controller function

didn't work for me, but this did work for me

php /path/to/the/project/index.php controller/function

Note the "/" between controller and function.

I have some cronjobs on my server. I simply call that controll that way: PHP Code:

/usr/bin/php /var/www/html/yourwebsite/index.php controllername functionname 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM