Accessing a CodeIgniter controller via CLI for usage within cron jobs

There are two ways to access CodeIgniter controllers from the CLI.

One is presented in the CodeIgniter documentation and it looks something like this:

The controller:

class Tools extends CI_Controller {

	public function message($to = 'World')
		echo "Hello {$to}!".PHP_EOL;

Calling it from the CI:

$ cd /path/to/project;
$ php index.php tools message

This method usually doesn’t work for me on the servers that I’ve used so far. It just goes to the default controller of the project.

The second method that always works for me involves using cURL:


One Comment

  1. If you don’t need to post data to the URI or have cookies (should not, considering cronjob scenario), you could also use wget.

Leave a Comment

Your email address will not be published. Required fields are marked *