A.Developer
A.Developer

Reputation: 43

Set cron job in Codeigniter

I am trying to run a script via cron job in cpanel. Maybe I entered a wrong path that's why I received a mail:

could not open input file.

Here is my code

class Cron extends CI_Controller
{

    public function run()
    {
        $this->load->library('email');   
        $this->email->to('[email protected]');
        $this->email->from('[email protected]','From');
        $this->email->subject('Cron');
        $this->email->message('Hello);
        $this->email->send();
    }
}

This code available in

public_html/folder/myproject/application/controller/Cron.php

But I dont know how to set this path in cron url

Upvotes: 0

Views: 434

Answers (2)

Amit Kumar PRO
Amit Kumar PRO

Reputation: 1240

Please try the following in cpanel command input

wget -q -O - http://www.yourdomain.com/cron/run >/dev/null 2>&1

Check the Screenshot enter image description here

If you want to do the same thing by file then please use proper path

/home/youruserdirectory/public_html/folder/myproject/application/controller/Cron.php

replace youruserdirectory to your current user directory.

Hope it will helpful.

Upvotes: 1

Vaviloff
Vaviloff

Reputation: 16856

Judging by your code the Cron controller has to be called from the web, not from command line, but that's fine, you don't necessarily have to provide cron job with the path on the server. You can run a command to make a request to your site like this:

*/5 * * * * /usr/bin/wget -qO- https://example.com/cron

The command in the example will make a request to your site every 5 minutes effectively running the Cron controller every time (in case you have not prevented access to it by its name with routing).

Upvotes: 0

Related Questions