Welcome Guest, Not a member yet? Register   Sign In
Codeigniter CLI does not log to database
#1

Hey Guys,

I tried asking this question on StackOverflow, but I think people do not have the correct knowledge to help me out. At least the one answer I got was not what I was looking for... So here goes.

I have the following function which updates the status of my vacancies (based on dates) and logs the amount of vacancies that got a change, it looks like this:


PHP Code:
    //Function used to check the statusses of every vacancy and update it accordingly
        function checkVacanciesStatusses()
        {
            // this function can only be called from the command line
            if (!$this->input->is_cli_request()) {
                echo "Access is only allowed from the command line";
                return;
            }
    
            $this
->load->model('vacancy/vacancies_model');
            $this->load->library('managers/LogManager');
    
            $affected0 
$this->vacancies_model->updateToStatus0();
            $this->logmanager->createCronLog("updateToStatus0"$affected0);
            $affected1 $this->vacancies_model->updateToStatus1();
            $this->logmanager->createCronLog("updateToStatus1"$affected1);
            $affected2 $this->vacancies_model->updateToStatus2();
            $this->logmanager->createCronLog("updateToStatus2"$affected2);
        


This is put in a cronjob to be executed every 30minutes, like so:

Code:
    */30 * * * * /usr/bin/php /var/www/index.php cli/cron checkVacanciesStatusses >/dev/null 2>&1


The code for the createCronLog in my logmanager looks like this:

   
PHP Code:
class LogManager {
    
        
protected $CI;
    
        
// We'll use a constructor, as you can't directly call a function
        // from a property definition.
        public function __construct()
        {
            // Assign the CodeIgniter super-object
            $this->CI =& get_instance();
            $this->CI->load->helper('url');
            $this->CI->load->model('logging/logCron_model');
        }
    
        
/**
         * Creates an entry in the log_cron table
         *
         * @param string $method            the name of the method executed
         * @param array  $amount_updated    the amount of rows updated during the method the cron logged for
         *
         * @return int                      row id
         */
        public function createCronLog($method$amount_updated)
        {
            //Create a LOG entry
            $entity = new stdClass();
            $entity->created_at date('Y-m-d H:i:s');
            $entity->hostname gethostname();
            $entity->pid getmypid();
            $entity->user get_current_user();
            $entity->uri $_SERVER['REQUEST_URI'];
            $entity->method $method;
            $entity->amount_updated $amount_updated;
    
            
return $this->CI->logCron_model->add($entity);
        }
    

The thing which I cannot wrap my head around is that the vacancy updates (so the model calls) work perfectly. But the logging does not work.

When I comment the if clause which checks if it is a cli_request, and I manually browse to the function, the vacancies gets updated AND the logging works!


What is happening? 
It is not giving any errors or whatsoever, it just works when executed manually.
Reply


Messages In This Thread
Codeigniter CLI does not log to database - by creawbe - 01-18-2018, 07:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB