skip to Main Content

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

2

Answers


  1. 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).

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search