[英]how to run cron in cpanel using codeigniter
如何使用codeigniter在cpanel中運行cron
<?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';
}
}
}
}
這是我的控制器-> Cron 文件。
我正在使用索引函數來使用 Cron 作業。
我在 cpanel /usr/bin/php /home/*****/public_html/*****/index.php cron index 中設置
還有我使用 php /full-path-to-cron-file/cron.php /test/index
您可以使用以下命令從命令行調用 codeigniter:
php /var/www/ci_folder/index.php controller_name function_name
參考這里: https : //www.codeigniter.com/userguide3/general/cli.html
我不知道為什么
php /path/to/the/project/index.php 控制器函數
對我不起作用,但這對我有用
php /path/to/the/project/index.php 控制器/函數
注意控制器和函數之間的“/”。
我的服務器上有一些 cronjob。 我只是這樣稱呼那個控件:PHP 代碼:
/usr/bin/php /var/www/html/yourwebsite/index.php controllername functionname
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.