dousongxuan7507 2017-03-27 13:47
浏览 71

如何使用codeigniter在cpanel中运行cron

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;
";
                $headers .= "From: ". $nameFrom . " <" . $mailFrom . ">
";                
                $headers .= "Reply-To: ". 'no-reply@gmail.com' . " <" . 'Project Board' . ">
";
                $headers .= "Return-Path: " . $mailFrom ."
";

                    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

  • 写回答

2条回答 默认 最新

  • doq91130 2017-03-28 10:16
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝