cron 作业在 codeigniter 中返回登录页面 html

问题描述 投票:0回答:2

在我的应用程序中,我需要设置 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

但是这会返回登录页面的 html,这也是应用程序的首页。 我认为路径有问题,那么我该如何修复它?

php codeigniter cron codeigniter-3
2个回答
2
投票

我发现你的代码和我工作的 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

如果有帮助请告诉我


0
投票

只需计数检查以确保文件名与控制器类名相同。

© www.soinside.com 2019 - 2024. All rights reserved.