繁体   English   中英

如何为 CodeIgniter 设置 cron 作业 URL?

[英]How to set cron job URL for CodeIgniter?

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

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

我是这样用的

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

它给出了“没有这样的目录”

如何在 cPanel 中为上述 URL 设置 cron jon。

利用:

php index.php welcome show

作为 crontab 中的命令。 例如:

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

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

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

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

我在cron下面使用过

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

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

这对我有用。

谢谢大家

你可以试试这个:

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

你也可以试试:

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

或本地主机

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

我希望这会有所帮助。

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

这对我有用。

这是我使用的 cron

在此处输入图像描述

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

解释:

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

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

c) 'cron' = 控制器名称

d) 'newsletter' = 方法名称

我已经做到了

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

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

我刚刚查看了此页面,该页面通过示例进行了非常详细的解释。 希望这对其他人也有用。

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

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

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

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

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

在 Linux EC2 实例上,这有效:

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

如果您使用的是 Hostgator(或任何其他 Linux 服务器),请尝试这个。

/opt/cpanel/ea-php72/root/usr/bin/php /YOUR_HOME_DIRECTORY/YOUR_USERNAME/public_html/marketing/index.php welcome emailcampaign 1

例如对我来说

/opt/cpanel/ea-php72/root/usr/bin/php /home3/adnan/public_html/index.php welcome emailcampaign 101

在哪里

welcome is the controller name
emailcampaign is the function name of welcome controller
101 = First argument of url.  

使用以下过程通过 cPanel 设置 cron 作业:

  1. 登录到您的 cPanel 界面。
  2. 转到“高级”部分。
  3. 单击“Cron 作业”。
  4. 从提供的列表中选择特定时间。
  5. 您应该在“命令”字段中输入要运行的命令。

在此处输入图像描述

如果您使用的是 cPanel,则使用以下命令:

/usr/bin/curl -k http://example.com/welcome/show

这对我来说非常有效。

我正在使用 hostgator 的 cPanel。
我在用户控制器中创建了一个用户控制器和run_cron_data函数。
命令: wget www.example.com/index.php/user/run_cron_data

看下面的截图

* * * * * php index.php controllername functionname

第 1 个 * - 分钟,第 2 个 * - 小时,第 3 个 * - 月中的某一天,第 4 个 * - 月,第 5 个 * - 星期几。

欲了解更多信息,请访问: https ://crontab.guru/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM