0

I want to set cron job using codeigniter, in godaddy shared hosting i used the following code to execute movies controller's cool method.

/web/cgi-bin/php5 "$HOME/html/MOVIESDOM.COM/index.php" movies cool

Problem is it always execute default controller.

Pls tell me how to execute movies controller's cool method

Edited by Prateek_2

6
Contributors
7
Replies
55
Views
2 Years
Discussion Span
Last Post by Arfan_1
1

you need to create routing directives for it.

$route['movies'] = "movies/cool";

assuming that you have movies.php in your application/controllers/ directory and it is coded something similar to this

class Movies extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {

        // you can do some other options as opposed to just cool method //

    }

    /* 
    * @cool method
    * execute cron job
    */

    public function cool()
    {

        //put your cron here
        // don't forget to run it on the background

        //catch cron-job log here if needed
        //if cron-job is successful return something or return true.

    }


    public function cron_status()
    {

        //this will check if the cron job log file exists
        // check the cron job status 
        // if a success return something 

        //call this method in the index method above, but make sure the reporting is only available to the administrator of the site.
      }

 //end of the class

 }

Another feasible option is to create a cron-job libraries and just load it whenever it is needed.

Edited by lorenzoDAlipio: information updated

0

@lorenzoDAlipio after setting up route config, it still executing home page

0

After further researching I was able to determine that there are two modes to php running: cgi or cli. Upon testing with php -v in shell I confirmed it was configured for cli, but running the same with a Cron job I saw the result being php running as cgi.

To resolve this I reconfigured my Cron job as follows:

/usr/local/bin/php /home/overstoc/www/admin/index.php cron update
I assume the default php that the Cron job is calling has a configuration for cgi where the server share is cli.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.