如何为codeigniter设置cron job url?

时间:2013-10-09 10:32:35

标签: php codeigniter cron

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

e.g。 http://my-domain.com/welcome/show,欢迎使用我的控制器,show是该控制器的功能名称。

我这样用过,

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

它给'没有这样的目录'

如何在CPANEL中为上面的URL设置cron jon。

感谢。

14 个答案:

答案 0 :(得分:34)

使用:

php index.php welcome show

作为crontab中的命令。 E.g:

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

答案 1 :(得分:17)

我使用了下面的cron

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

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

这适合我。

感谢所有

答案 2 :(得分:11)

你可以试试这个:

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

答案 3 :(得分:8)

您也可以尝试:

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

或localhost

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

我希望这有用。

答案 4 :(得分:4)

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

这对我有用。

答案 5 :(得分:2)

这是我使用的cron

enter image description here

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

说明:

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

b)codeigniter网站root = / home / pia / www / jobs

c)' cron' =控制器名称

d)' newsletter' =方法名称

答案 6 :(得分:1)

我已经完成了

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

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

我刚刚查看了this page,它通过示例解释了非常详细的内容。希望这对其他人也有用。

答案 7 :(得分:1)

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

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

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

答案 8 :(得分:0)

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

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

答案 9 :(得分:0)

在Linux EC2上,这很有效:

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

答案 10 :(得分:0)

使用以下过程通过cPanel设置cron作业: 1-登录到您的cPanel界面。 2-转到“高级”部分。 3-单击“ Cron Jobs”。 4-从提供的列表中选择特定时间。 5-您应该在“命令”字段中输入要运行的命令。enter image description here

答案 11 :(得分:0)

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

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

这对我来说很好。

答案 12 :(得分:0)

如果您使用的是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.  

答案 13 :(得分:0)

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

请看下面的截图 enter image description here