Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set cron job url for codeigniter?

I am using CodeIgniter for my website. I have to use cron job to run one of controller function. I am using route in website. And also I am not using index.php in URL.

e.g. http://example.com/welcome/show, here welcome is my controller and show is function name of that controller.

I have used like this,

0 * * * * php /home/username/public_html/welcome/show

It is giving 'No such directory'

How can I set cron jon in cPanel for above URL.

like image 626
Sachin Avatar asked Oct 09 '13 10:10

Sachin


People also ask

What is cron job in CodeIgniter?

Building a command line interface into your application can be a way to add extra utility to your application. Adding cron jobs (a.k.a. scheduled tasks) to your CodeIgniter application can provide additional utility.

Where are Cronjobs run?

Cron jobs are typically located in the spool directories. They are stored in tables called crontabs. You can find them in /var/spool/cron/crontabs. The tables contain the cron jobs for all users, except the root user.


4 Answers

Use:

php index.php welcome show

as command in your crontab. E.g.:

0 * * * * php /home/username/index.php welcome show

Source (ver. 2.2.0) http://www.codeigniter.com/userguide2/general/cli.html

Source (ver. 3.*) http://www.codeigniter.com/user_guide/general/cli.html

Source (ver. 4.*) http://codeigniter.com/user_guide/cli/cli.html

like image 151
unicorn80 Avatar answered Sep 29 '22 05:09

unicorn80


I have used below cron

php /full-path-to-cron-file/cron.php /test/index

source: http://www.asim.pk/2009/05/14/creating-and-installing-crontabs-using-codeigniter/

This works for me.

Thanks to all

like image 24
Sachin Avatar answered Sep 29 '22 05:09

Sachin


You can try with this one:

wget api.example.com/index.php/controller/function
like image 20
Suvash sarker Avatar answered Sep 29 '22 04:09

Suvash sarker


You can also try:

0 * * * * /usr/bin/curl --silent --compressed http://example.com/welcome/show

Or localhost

0 * * * * /usr/bin/curl --silent --compressed http://localhost/welcome/show

I hope that is helpful.

like image 27
alditis Avatar answered Sep 29 '22 06:09

alditis