How to set cron job url for codeigniter?

2019-01-08 10:31发布

问题:

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://my-domain.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.

Thanks.

回答1:

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



回答2:

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



回答3:

You can try with this one:

wget api.example.com/index.php/controller/function


回答4:

You can also try:

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

Or localhost

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

I hope that is helpful.



回答5:

/usr/local/bin/php /home/username/public_html/index.php controllername methodname

This worked for me.



回答6:

Here is the cron I use

/usr/bin/php /home/pia/www/jobs/index.php cron newsletter

Explanation:

a) $_SERVER['DOCUMENT_ROOT'] = /home/pia/www

b) codeigniter website root = /home/pia/www/jobs

c) 'cron' = controller name

d) 'newsletter' = method name



回答7:

I have done it as

 00 09-18 * * 1-5 /usr/bin/php /var/www/html/app/index.php crontest

crontest is the name of the controller which also uses a model to pull data from the database and send mail periodically (between 9 AM to 6 PM on Monday to Friday every week)

I just viewed this page which explains very detail with example. Hope this will be useful to others as well.



回答8:

I am using codeigniter 3.0.3 and my server is hostgator. For me, the below format is working fine

*/15 * * * * /opt/php55/bin/php /home/username/public_html/myapp/index.php reminders index

above command runs every 15 minutes, reminders in command is controller name and index is method name.



回答9:

watch -n60 curl [your application path]/check_banalce/user_balance

in my case im using codeigniter and the above command executes the user_balance function which is found in check_balance controller every 60 sec.



回答10:

On a Linux EC2 intance, this worked:

*/5 * * * * /usr/bin/php /var/www/html/cifolder/index.php [module] [function]