douci7521 2014-02-24 04:22
浏览 38
已采纳

CodeIgniter - 每小时方法调用

I'm using CodeIgniter for my project. I have this roadblock in from of me..

There's this method in my controller that I want to call every hour. Let's have that as:

class Notifs extends CI_Controller {

    public function __construct() {
        parent:: __construct();
        // load stuff here
    }

    public function index() {

    }

    /* I want to call this function on an hourly basis */
    public function check_overdue_stuffs() {
        // do the checking here
    }

}

I have absolutely no idea on how to implement this. I have tried using sleep($seconds) but that was just a mess.

Any ideas for a perfectly awesome way to do this? A verbose example would be great. Thanks!

  • 写回答

1条回答 默认 最新

  • douqianxian7008 2014-02-24 05:17
    关注

    This is pretty straight forward, but don't look to just keeping it in your PHP code. You need to use a cronjob script (linux) or windows equivalent (on the server where your software lives).

    Here is a simple cron you would add to pull a specific cli method:

    # hourly cron
    0 * * * * php /www/ciWebsite/index.php [controller] [method] >/dev/null 2>&1
    

    That way, it runs the controller + method you want and output is dumped into /dev/null

    Try running /www/ciWebsite/index.php notifs check_overdue_stuff and see if it works (obviously update your path)

    edit:

    • fixed an extra entry (I had cli = folder + controller + method)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题