Codeigniter 中的 Cronjob

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cron extends CI_Controller 
{
    /**
     * This is default constructor of the class
     */
    public function __construct()
    {
        parent::__construct();
        $this->load->library('input');
        $this->load->model('cron_model');
    }
    
    /**
     * This function is used to update the age of users automatically
     * This function is called by cron job once in a day at midnight 00:00
     */
    public function updateAge()
    {            
        // is_cli_request() is provided by default input library of codeigniter
        if($this->input->is_cli_request())
        {            
            $this->cron_model->updateAge();
        }
        else
        {
            echo "You dont have access";
        }
    }
}
?>

請按照以下方式從 cpanel / cron 管理器中呼叫此方法(我新增了更多方法來呼叫它):

0 0 0 0 0 php-cli /home/your_site_user/public_html/index.php cron updateAge

要麼

0 0 0 0 0 wget http://your_site_url/cron/updateAge

要麼

0 0 0 0 0 /usr/bin/php /home/your_site_user/public_html/index.php cron updateAge

就我而言:wget 是在 plesk 和 cpanel 上工作(wget 在根目錄下的伺服器上建立檔案)。php-cli 適用於 plesk 和 cpanel。