ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# think-cron 计划任务 ## [](https://github.com/yunwuxin/think-cron/blob/3.0/README.md#安装方法)安装方法 ~~~ composer require yunwuxin/think-cron ~~~ ## [](https://github.com/yunwuxin/think-cron/blob/3.0/README.md#使用方法)使用方法 ### [](https://github.com/yunwuxin/think-cron/blob/3.0/README.md#创建任务类)创建任务类 ~~~ <?php namespace app\task; use yunwuxin\cron\Task; class DemoTask extends Task { public function configure() { $this->daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释 } /** * 执行任务 * @return mixed */ protected function execute() { //...具体的任务执行 } } ~~~ ### [](https://github.com/yunwuxin/think-cron/blob/3.0/README.md#配置)配置 > 配置文件位于 application/extra/cron.php ~~~ return [ 'tasks' => [ \app\task\DemoTask::class, //任务的完整类名 ] ]; ~~~ ### [](https://github.com/yunwuxin/think-cron/blob/3.0/README.md#任务监听)任务监听 #### [](https://github.com/yunwuxin/think-cron/blob/3.0/README.md#两种方法)两种方法: > 方法一 (推荐) 起一个常驻进程,可以配合supervisor使用 ~~~ php think cron:schedule ~~~ > 方法二 在系统的计划任务里添加 ~~~ * * * * * php /path/to/think cron:run >> /dev/null 2>&1 ~~~