codeigniter 中的 cron 作业 return 登录页面 html

cron job return login page html in codeigniter

在我的应用程序中,我需要设置 cron 作业以进行每日更新。我正在使用 CodeIgniter 3.0

我的config.php文件

$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

这是我的控制器

class Cron extends CI_Controller {

public function cron_job(){
    if (!$this->input->is_cli_request()){
        echo 'test';
        //show_error('Direct access is not allowed');
    }
    else{
        echo 'call';
    }

    }
}

并且我在 cpenal 中设置了路径,例如

/usr/bin/php /home/public_html/my_app/index.php cron cron_job

但是这个 return html 登录页面也是应用程序的首页。 我认为路径有问题,那么我该如何解决?

我发现你的代码和我的 CI3 cronjobs 有两个主要区别。

首先是我使用 if (is_cli()) 而不是 if (!$this->input->is_cli_request()){

其次,可能取决于您的服务器设置,但请尝试在 /usr/bin/php 之后添加 -cli,就像我在这里所做的那样:

/usr/bin/php-cli /home/public_html/index.php cron cron_job

如果有帮助请告诉我