zoukankan      html  css  js  c++  java
  • laravel调度任务

    <?php

    namespace AppConsole;

    use IlluminateConsoleSchedulingSchedule;
    use IlluminateFoundationConsoleKernel as ConsoleKernel;
    use IlluminateSupportFacadesDB;

    class Kernel extends ConsoleKernel
    {
    /**
    * The Artisan commands provided by your application.
    *
    * @var array
    */
    protected $commands = [
    AppConsoleCommandsInspire::class,
    ];

    /**
    * Define the application's command schedule.
    *
    * @param IlluminateConsoleSchedulingSchedule $schedule
    * @return void
    */
    protected function schedule(Schedule $schedule)
    {

    $schedule->exec(
    $schedule->call(function () {
    DB::table('ceshi')->insert(['contents'=>'新的数据']);
    })->everyMinute()
    )->daily();
    }
    }

    执行调度任务,添加Crontab定时任务,
    用命令crontab -e 添加如下内容

    * * * * * /usr/local/bin/php /usr/local/var/www/projectName/artisan schedule:run >> /dev/null 2>&1
    
    • 1
    • 2

    如图:
    这里写图片描述
    上面命令Crontab会每分钟去调Laravel的schedule命令,然后Laravel判断执行任务。

  • 相关阅读:
    C语言第三天,《常量指针和指针常量》
    树莓派系统烧入总结
    c 语言第一天
    7. Vue
    6. Vue
    5. Vue
    4. Vue
    3. Vue
    1. Vue
    2. Vue
  • 原文地址:https://www.cnblogs.com/isuansuan/p/9700745.html
Copyright © 2011-2022 走看看