ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
目录结构 - ![](https://box.kancloud.cn/04fdc2e2f3771931a9f48354abb09b5d_666x413.png) - 编写代码 ~~~ <?php /** * @Author: 陈静 * @Date: 2018/04/18 22:16:15 * @Description: 这里借鉴的是 https://www.kancloud.cn/mikkle/thinkphp5_study/376459 */ namespace app\console; use think\Cache; use think\console\Command; use think\console\Input; use think\console\Output; class TaskTest extends Command { protected $sleep = 3; protected function configure() { $this->setName('task_test')->setDescription('Here is the task test command '); } protected function execute(Input $input, Output $output) { while(true){ $output->writeln(json_encode($this->checkDo())); sleep($this->sleep); } } protected function checkDo(){ $state = false; $int = Cache::inc("Command",1); //这里根据查询的缓存内容 或者时间 写你的逻辑代码 //---------------- // you code //-------------- return $int; } } ~~~ - 添加命令 ![](https://box.kancloud.cn/c5f0834bcc3b3553c2fcaa3ae92976b3_620x394.png) - 执行命令 `php think task_test` 效果 - ![](https://box.kancloud.cn/8608438e3ee2969a18868c180bb201b4_465x139.png)