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。