thinkPhp 任务调度
2022-11-24 11:10:29
202
{{single.collect_count}}

1.书写任务,最好在app/command下,不在也没关系 

<?php/* * 修改已过期广告状态 * @user YangYunHao * @time 2020-07-21 14:36:51 * */namespace app\cli;use think\console\Command; // 这个是必须的use think\console\Input; // 这个是必须的use think\console\Output; // 这个是必须的// 也必须交继承class UpdateOverdueAdvState extends Command{protected function configure(){//超时未接单自动关闭$this->setName('update_overdue_adv_state')->setDescription('修改过期广告状态');}protected function execute(Input $input, Output $output){// 这里写逻辑,处理数据}}

2.在app/command.php里面加上 你刚才写的任务命名空间名称

<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.// +----------------------------------------------------------------------// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )// +----------------------------------------------------------------------// | Author: yunwuxin <448901948@qq.com>// +----------------------------------------------------------------------return ['app\cli\UpdateOverdueAdvState' // 修改过期广告状态];

3.测试。在项目根目录内查看都有哪些任务执行 php think

4.项目根目录执行 php think update_overdue_adv_state 就可以运行程序了

5.添加带定时任务中

* * * * * php /Users/AarthiModoo/Desktop/E/work/limingjiaobu-api/think update_overdue_adv_state// 如果执行不成功 将php写为全路径如下(每个人的不一样)* * * * * /usr/local/php5/bin/php /Users/AarthiModoo/Desktop/E/work/limingjiaobu-api/think update_overdue_adv_state

 

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}