Tweet
submit to reddit
<? mildcoder ?>
Home | About Me | Contact Us
Categories
  • Security
  • Research
  • Classes
  • Downloads
  • Tutorials
  • News
Search
Advertisements

Handling Codeigniter in CLI and Cron Jobs

Here i am writing about how to execute codeigniter applications from commandline or cron jobs. Its not complicated as you think. Its clearly mentioned in its documentation but we all are not aware of it. By referring the following example you can implement it.


Codeigniter.

Example controller:

1
2
3
4
5
6
7
8
9
10
11
<?php
class Example extends CI_Controller
{
    public function index() {
        echo "Foo, Bar" . PHP_EOL;
    }

    public function test($bar) {
        echo "Foo, $bar" . PHP_EOL;
    }
}

Find the absolute path to your index.php file located in the codeigniter root directory. Then open the terminal and enter as given below. If you are not in the root folder of your application or if you are executing it from the cron job, you will have to provide the absolute path of the index file.

Calling the Controller:

1
php index.php example

Calling an Action from the Controller:

1
php index.php example index

Calling an Action from the Controller along with the parameters:

1
php index.php example test bar

If you want to make a call through the http protocol, you can follow the way given below:

1
wget http://example.com/example/test/bar/

or

1
curl http://example.com/example/test/bar/

If the wget or curl commands are not installed in your server, you can have it installed by executing the following command:

1
sudo apt-get install wget
1
sudo apt-get install curl