美文网首页
laravel 任务调度

laravel 任务调度

作者: 李科震 | 来源:发表于2017-12-11 11:20 被阅读0次

    创建定时任务文件

    php artisan make:command Schedules
    

    编辑文件内容

    1: 修改 protected $signature = 'schedules';
    schedules: 用做 php artisan 命令 (php artisan schedules)
    2: 在 handle 里面编写逻辑信息
    

    修改Kernel 文件

    1. 找到protected $commands
      eg: 
        protected $commands = [
            \App\Console\Commands\Schedules::class
        ];
    2. 修改方法 schedule()
      eg: 
        protected function schedule(Schedule $schedule)
        {
            $schedule->command('Schedules')->everyMinute();
        }
    

    添加定时任务

    1. crontab -e 打开定时任务编辑(如果不能执行,先安装 cron)
    2. 编辑
      eg: path/to/ 是你的项目路径
      * * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
    

    相关文章

      网友评论

          本文标题:laravel 任务调度

          本文链接:https://www.haomeiwen.com/subject/zdciixtx.html