当前位置:网站首页>laravel+宝塔计划任务

laravel+宝塔计划任务

2022-06-22 19:26:00 香橙战宝橙留香

先在本地执行php artisan make:command job

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class job extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:name';//生成的任务名称

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

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

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()//要执行的任务
    {
        DB::table('home')->where('id',1)->increment('num',1);
    }
}
<?php

namespace App\Console;

use App\Console\Commands\job;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
         $schedule->command(job::class)->everyMinute();//调用执行的任务
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

将项目上传上传到宝塔

填写计划任务

 

原网站

版权声明
本文为[香橙战宝橙留香]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq7689095/article/details/125397285