当前位置:网站首页>Laravel task scheduling

Laravel task scheduling

2022-06-25 12:34:00 qq_ twenty-five million sixty thousand seven hundred and sixty-

First, start task scheduling

adopt  crontab -e  To add or edit scheduled tasks , adopt  crontab -l  View existing scheduled tasks

* * * * * / Yours php The location of /php / Your project location /artisan schedule:run >> /dev/null 2>&1

Define scheduling

php artisan make:command Test \\App\Console\Commands\Test.php

<?php namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
use Log;

class Test extends Command {

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test'; // Command name 

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = ' Task test '; // Command description 

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        Log::info('66666');
    }

}

app/Console/Kernel.php file

<?php namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel {

    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        \App\Console\Commands\Test::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('test') //Test.php Medium name
                 ->everyMinutes(); // Execute every minute 
    }

}

Scheduling common options

Method describe
->cron('* * * * *'); In the custom Cron Running tasks on a schedule
->everyMinute(); Run the task every minute
->everyFiveMinutes(); Run the task every five minutes
->everyTenMinutes(); Run the task every ten minutes
->everyFifteenMinutes(); Run the task every 15 minutes
->everyThirtyMinutes(); Run the task every 30 minutes
->hourly(); Run the task every hour
->hourlyAt(17); Run the task every seventeen minutes of the hour
->daily(); Run the mission at 0 a.m. every morning
->dailyAt('13:00'); Every day 13:00 Run the task
->twiceDaily(1, 13); Every day 1:00 & 13:00 Run the task
->weekly(); Run the task once a week
->monthly(); Run the task once a month
->monthlyOn(4, '15:00'); monthly 4 Number 15:00 Run a task
->quarterly(); Run Quarterly
->yearly(); Run once a year
->timezone('PRC'); Set time zone
原网站

版权声明
本文为[qq_ twenty-five million sixty thousand seven hundred and sixty-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200529390557.html

随机推荐