从cronjob运行时,CodeIgniter is_cli_request()返回false [英] CodeIgniter is_cli_request() returns false when run from cronjob

查看:66
本文介绍了从cronjob运行时,CodeIgniter is_cli_request()返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的cronjob的命令

Here is my cronjob's command


php /home/toolacct/public_html/index.php cronjob fetch_emails

php /home/toolacct/public_html/index.php cronjob fetch_emails

这是我的CodeIgniter cronjob控制器


Here is my CodeIgniter cronjob controller

class Cronjob extends CI_Controller {
    function __construct() {
        parent::__construct();
        die($this->input->is_cli_request()?'T':'F');
        $this->load->model('cronjob_model');
    }   

    public function fetch_emails() {
        $this->cronjob_model->fetch_emails();
    }

    public function index_popularity() {
        $this->db->query('CALL update_email_data_popularity()');
    }
}

cronjob会说 F
为什么?

The cronjob says "F" Why?

注意:如果我创建这样的函数

A side note: If I create a function like this

function is_cli_request() {
    return isset($_SERVER['SHELL']);
}

它正确返回true或false,而CodeIgniter总是返回false。

It returns true or false correctly, while CodeIgniter always returns false.

推荐答案

输入类文档说, $ this-> input-> is_cli_request()使用STDIN常量检查其是否在命令上运行

The Input Class Documentation says that $this->input->is_cli_request() uses the STDIN constant to check if its running on the command line.

尝试使用PHP的命令行版本(php-cli),因为在运行标准PHP可执行文件时似乎未设置STDIN常量( php)。

Try using the command line version of PHP instead (php-cli), since the STDIN constant doesn't appear to be set while running the standard PHP executable (php).

这篇关于从cronjob运行时,CodeIgniter is_cli_request()返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆