php 如何为codeigniter设置cron作业网址?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19269566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 19:09:27  来源:igfitidea点击:

How to set cron job url for codeigniter?

phpcodeignitercron

提问by Sachin

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.

我正在为我的网站使用 Codeigniter。我必须使用 cron 作业来运行控制器功能之一。我在网站上使用路线。而且我没有在 url 中使用 index.php。

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

例如http://my-domain.com/welcome/show,这里welcome 是我的控制器,show 是该控制器的函数名称。

I have used like this,

我是这样用的

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

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.

如何在 CPANEL 中为上述 url 设置 cron jon。

Thanks.

谢谢。

采纳答案by Sachin

I have used below cron

我在 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/

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

This works for me.

这对我有用。

Thanks to all

谢谢大家

回答by unicorn80

Use:

用:

php index.php welcome show

as command in your crontab. E.g.:

作为 crontab 中的命令。例如:

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

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

来源(版本 2.2.0) http://www.codeigniter.com/userguide2/general/cli.html

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

来源(版本 3.*) http://www.codeigniter.com/user_guide/general/cli.html

回答by Suvash sarker

You can try with this one:

你可以试试这个:

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

回答by alditis

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.

我希望这是有帮助的。

回答by Reshma D

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

/usr/local/bin/php /home/username/public_html/index.php 控制器名 方法名

This worked for me.

这对我有用。

回答by Florin

Here is the cron I use

这是我使用的 cron

enter image description here

在此处输入图片说明

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

/usr/bin/php /home/pia/www/jobs/index.php cron 通讯

Explanation:

解释:

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

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

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

b) codeigniter 网站根目录 = /home/pia/www/jobs

c) 'cron' = controller name

c) 'cron' = 控制器名称

d) 'newsletter' = method name

d) '时事通讯' = 方法名称

回答by Rajesh

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)

crontest 是控制器的名称,它也使用模型从数据库中提取数据并定期发送邮件(每周一至周五的上午 9 点至下午 6 点之间)

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

我刚刚查看了这个页面,它通过示例解释了非常详细的信息。希望这对其他人也有用。

回答by prudhvi259

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

我使用的是 codeigniter 3.0.3,我的服务器是 hostgator。对我来说,以下格式工作正常

*/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.

上面的命令每 15 分钟运行一次,命令中的提醒是控制器名称,索引是方法名称。

回答by Devaniyas

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.

在我的情况下,我使用 codeigniter,上面的命令每 60 秒执行一次在 check_balance 控制器中找到的 user_balance 函数。

回答by ssaltman

On a Linux EC2 intance, this worked:

在 Linux EC2 实例上,这有效:

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