laravel 定时任务 宝塔添加定时任务

1、php artisan make:command Test

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'insert Test table some test data';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //需要执行的方法写在handle中
        Log::info('123');
    
    }

注册路由命令调整kernel.php文件
路径:app\console\kernel.php

 /**
     * 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)
    {
    //command里面写定时任务的$signature的值
         $schedule->command('test')
                  ->everyMinute();
    }

设定定时任务时间

->cron('* * * * *');    在自定义Cron调度上运行任务
->everyMinute();    每分钟运行一次任务
->everyFiveMinutes();   每五分钟运行一次任务
->everyTenMinutes();    每十分钟运行一次任务
->everyThirtyMinutes(); 每三十分钟运行一次任务
->hourly(); 每小时运行一次任务
->daily();  每天凌晨零点运行任务
->dailyAt('13:00'); 每天13:00运行任务
->twiceDaily(1, 13);    每天1:00 & 13:00运行任务
->weekly(); 每周运行一次任务
->monthly();    每月运行一次任务
->monthlyOn(4, '15:00');    每月4号15:00运行一次任务
->quarterly();  每个季度运行一次
->yearly(); 每年运行一次
->timezone('America/New_York'); 设置时区

宝塔设置
在这里插入图片描述
脚本内容写规则:php路径 文件路径/artisan schedule:run >> /dev/null 2>&1
例如:/www/server/php/72/bin/php /www/wwwroot/ceshi/artisan schedule:run >> /dev/null 2>&1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值