CodeIgniter is_cli_request() returns false when run from cronjob

佐手、 提交于 2019-12-11 00:56:56

问题


Here is my cronjob's command

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

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()');
    }
}

The cronjob says "F" Why?


A side note: If I create a function like this

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

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


回答1:


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

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).



来源:https://stackoverflow.com/questions/9285034/codeigniter-is-cli-request-returns-false-when-run-from-cronjob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!