Question

I am trying to set up a cron job using COdeigniter but I cannot figure out how to get it to work. I have a file called email_check.php in my controllers folder, and I have added a .cron file to the servers cron folder, which contains the following

email_check.cron

*/1 * * * * php /var/www/html/application/controllers/email_check

email_check.php

class Email_check extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->index();
    }

    function index()
    {
        $this->load->model('admin/info_model'); 
        $this->info_model->addTestData();
    }

}

The addTestData adds a new row into a database table. I would like this to run every minute, however it isn't working at all and I have no idea why.

Maybe it may be the paths that are wrong. Do I need to point the php part to the php.exe in the server.

If anyone could help or point me in the right direction it would be greatly appreciated!

Was it helpful?

Solution

To use CodeIgniter via the commmand line, you need to call the index.php file and pass in the controller and method as arguments, plus any other arguments. So at the minimum the cron job call would be:

~/public_html/sitefolder/index.php controller method

Or using the path to your application index file. But, you also need to use PHP compiled for the command line, not just PHP for CGI-FCGI. So your call might be something like:

/ramdisk/bin/php5-cli ~/public_html/sitefolder/index.php controller method

Depending on where your PHP CLI is located.

OTHER TIPS

This won't work because just hitting your email_check.php controller won't do anything because its not going to call your index() method.

You want to either write a script that is going to create a new instance of the controller and call the method or call it via a URL, something like this I think

* * * * * wget http://sitename.com/email_check
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top