CodeIgniter Forums
How to use $this->input->is_cli_request() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How to use $this->input->is_cli_request() (/showthread.php?tid=63696)



How to use $this->input->is_cli_request() - hikaru2838 - 11-29-2015

Hi, i want to test cron job and check it. But i don't know how to use $this->input->is_cli_request(). My controller
PHP Code:
defined('BASEPATH') OR exit('No direct script access allowed');

class 
Welcome extends CI_Controller {
 public function 
__construct() {
 
       parent::__construct();
 
       $this->load->helper('url');
 
       $this->load->helper('security');
 
       $this->load->library("session");
 
       $this->load->library('form_validation');
 
       $this->load->helper('date');
 
       $this->load->helper('string');
 
   }
 public function 
index()
 {

 
$dates "%Y-%m-%d %H:%i:%s"  $time time();
 
$this->load->model("msite");
 
$data_insert = array(
 
              "time"    => mdate($dates$time),
 
          );
 
       $this->msite->insertT($data_insert);
 
$this->load->view('welcome_message');
 }

And cron job in my host
PHP Code:
php public_html/test/index.php welcome index >> /dev/null 

It can run and add in my database but when i add $this->input->is_cli_request(). It can't run - What can i edit cron job in host?

PHP Code:
defined('BASEPATH') OR exit('No direct script access allowed');

class 
Welcome extends CI_Controller {
 public function 
__construct() {
 
       parent::__construct();
 
       $this->load->helper('url');
 
       $this->load->helper('security');
 
       $this->load->library("session");
 
       $this->load->library('form_validation');
 
       $this->load->helper('date');
 
       $this->load->helper('string');
 
   }
 public function 
index()
 {
 if(!
$this->input->is_cli_request())
 
 {
 
     echo "Not run";
 
     return;
 }

 
$dates "%Y-%m-%d %H:%i:%s"  $time time();
 
$this->load->model("msite");
 
$data_insert = array(
 
              "time"    => mdate($dates$time),
 
          );
 
       $this->msite->insertT($data_insert);
 
$this->load->view('welcome_message');
 }