3

I'm trying to create a cron job on cpanel using this command:

/usr/bin/php -q /home/mystuff/public_html/application/controllers/scripts.php scripts release_reviews

My scripts.php controller is as follows:

<?php

class Scripts extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        if (!$this->input->is_cli_request()) show_error('Direct access is not allowed');

    }

    public function release_reviews()
    {
        echo release_reviews(); //where the actual logic will sit once the cron job works
    }
}

The feedback I get when I try to run the cron job: Fatal error: Class 'CI_Controller' not found in /home/mystuff/public_html/application/controllers/scripts.php on line 3

I can't find any evidence anyone has the same problem as me - most topics around this do the same as me and it works just fine apparently.

Thanks a lot in advance!

Davor
  • 1,227
  • 4
  • 15
  • 31

3 Answers3

4

To access CodeIgnter via the command line, you want to call the index.php file, not your controller.

php /home/mystuff/public_html/index.php scripts release_reviews

Docs: http://ellislab.com/codeigniter/user-guide/general/cli.html

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • I have tried exactly that but it now says "404 Page Not Found". The index.php is however definitely located where I stated. – Davor Dec 14 '12 at 00:21
  • I was actually just trying that as well - the cron job just doesn't run anymore if I add "local". So that doesn't seem to be the issue. – Davor Dec 14 '12 at 00:36
  • @Davor: I'm not sure what to tell ya. Is CodeIgniter configured fully? – gen_Eric Dec 14 '12 at 00:42
  • Well I have a fully working website so CI is configured fully (at least CI_Controller or MY_Controller are working in the application). Thx for your help, hopefully a miracle happens and the solutions pops up at some point! – Davor Dec 14 '12 at 01:00
  • What CI version are you using? CLI was kinda flaky in the 1.7.x series. – gen_Eric Dec 14 '12 at 03:34
0

There is no CI_Controller class. CRON jobs only load that file, so it can't find any CI_Controller. You are going to have to include the CI_CONTROLLER class before the class definition

Something like this

<?php

require_once('path_to_CI_controller');

class Scripts extends CI_Controller
{
    ...
christopher
  • 615
  • 5
  • 11
0

Used the following in the routes file and it worked! I figured this out. My newbie problem is that the arguments need to be configured.

e.g.

`$route['pdfscript/runmethod']  = "batch/pdfscript/runmethod";
$route['pdfscript/runmethod/(:any)'] = "batch/pdfscript/runmethod/$1";'

`pdfscript.php
<?php 
class pdfscript extends CI_Controller {
public function runmethod($file) {
echo $file;
.....`

cmd line> php.exe index.php pdfscript runmethod filename