Search code examples
phpcodeignitercroncodeigniter-3

cron job return login page html in codeigniter


In my application i need to set cron job for daily updation. I am using CodeIgniter 3.0

My config.php file

$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

Here is my controller

class Cron extends CI_Controller {

public function cron_job(){
    if (!$this->input->is_cli_request()){
        echo 'test';
        //show_error('Direct access is not allowed');
    }
    else{
        echo 'call';
    }

    }
}

and i have set path in cpenal like

/usr/bin/php /home/public_html/my_app/index.php cron cron_job

But this return html of login page which is also front page of app. I think there is issue with path, So how can i fix it?


Solution

  • I see two main differences between your code and my working CI3 cronjobs.

    First is I use if (is_cli()) instead of if (!$this->input->is_cli_request()){.

    Second, and may depend on your server settings but try adding -cli after /usr/bin/php as I have here:

    /usr/bin/php-cli /home/public_html/index.php cron cron_job
    

    Please let me know if this helps