Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter is_cli_request() returns false when run from cronjob

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.

like image 938
Farzher Avatar asked Jul 27 '26 10:07

Farzher


1 Answers

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

like image 68
Quetzy Garcia Avatar answered Jul 29 '26 19:07

Quetzy Garcia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!