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)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源