How to run a Codeigniter php file using cronjob in ubuntu?

Viewed 91

So i have this php function path in codeigniter which I am trying to run through cron job in ubuntu. But whatever I have tried it is not working. The command I have tried so far

* * * * * /usr/bin/php http://localhost/QAPIv2/updateTestData

But it is not executing. I am using codeigniter

3 Answers

To elaborate on Rohan's answer, you run the functions like php index.php controller function. So, for example, to run your script every Tuesday at 8:31AM, your crontab entry should look like :

31 08 * * 2 cd /path/to/codeigniter; /usr/bin/php index.php QAPIv2 updateTestData;

Try this:

*/1 * * * * /usr/bin/php /var/www/html/YOUR PROJECT FOLDER NAME/index.php YOUR FUNCTION NAME > /dev/null 2>&1

First number is time for cron.In function name you should give the controller function name which you want to load in cron.

Please call the function from the command line.

$ cd /path/to/project;
$ php index.php controller function

Please change the controller and function according to your code.

Related