4

I'm trying to set up a CRON job to make some database changes on a CodeIgniter install and having issues with the host that are stopping it from working. The host's CRON setup only allows you to execute a PHP file rather than calling a URL.

What I've tried:

Curl, wget, file_get_contents, fopen, http_get from a static PHP file - all not allowed by the host

/path/to/php /path/to/index.php controller method - to use the command line interface

After unfruitful conversations with the host I'm out of ideas. Does anyone know how I could call a controller method from a static PHP file without the above?

YakovL
  • 7,557
  • 12
  • 62
  • 102
PaulK
  • 114
  • 1
  • 1
  • 6
  • I use the CLI method and it works... what version of PHP? do you know your host's flavor of Linux? – Marc Audet Mar 17 '13 at 17:13
  • Are you working on a shared host or a virtual dedicated server (VPS)? – Marc Audet Mar 17 '13 at 17:25
  • I'm not completely sure what exact flavour of Linux it is, or how to find out, but I can see this under phpinfo: x86_64-redhat-linux-gnu . The commands can be run through PHP 4 or PHP 5.2 and it's on a shared host – PaulK Mar 17 '13 at 17:35
  • Your best bet might be to post something on the community forum or bulletin board of our hosting company (if possible). This issue is very server dependent. Sorry I can't be of much help. – Marc Audet Mar 17 '13 at 21:53
  • try this solutions http://stackoverflow.com/questions/7322378/cron-jobs-in-codeigniter – san4o Mar 18 '13 at 13:58
  • Thanks for the tips / link but still no joy - the host seems to have locked down anything but direct file execution - still open to ideas – PaulK Mar 18 '13 at 20:02

1 Answers1

1

First of all, I'm assuming you are using CI ver 2> (CLI support was not available before).

Secondly, lets say that the page you are trying to fire under cron is http://www.mysite.com/index.php/cronjobs/thejob

The correct command would be:

/usr/bin/php /var/www/rootCIfolder/index.php cronjobs thejob

Replace /usr/bin/php with the location of your php executable and /var/www/rootCIfolder with the location of your CI folder.

You need to have php compiled with command line support. You can verify this by:

# php -v
PHP 5.3.3 (cli) (built: Jul  3 2012 16:53:21)
Iraklis
  • 2,762
  • 1
  • 24
  • 31