关于laravel的定时任务

本文介绍了在Laravel框架中创建和配置定时任务的过程。首先通过`php artisan make:console`命令生成命令类,然后将其注册到AppConsoleKernel的$commands属性。执行命令后,再利用crontab设置定时任务,确保每分钟执行一次`laravel:academy`命令。详细阐述了cron语法和特殊符号的含义。
摘要由CSDN通过智能技术生成

首先要明确使用定时的这种业务场景:
规定的时间执行某个操作或者执行一条sql语句。
1 创建一条命令
php artisan make:console HelloLaravelAcademy –command=laravel:academy
执行完成后会在app/Console/Commands下生成一个 HelloLaravelAcademy的文件。

<?php

namespace App\Console\Commands;

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

class HelloLaravelAcademy extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'inspire';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Display an inspiring quote';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //$this->comment(PHP_EOL.Inspiring::quote().PHP_E
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值