Home >Backend Development >PHP Tutorial >Detailed explanation of Laravel's task scheduling console

Detailed explanation of Laravel's task scheduling console

*文
*文Original
2018-01-03 13:00:322757browse

This article mainly gives you a brief introduction to how to use the task scheduling console in Laravel, and attaches a simple example. I hope it will be helpful for everyone to learn to use the console.

Applicable scenarios: analysis data (log)

php artisan make:console 你的命令类名

Example:

php artisan make:console Check

A Check.php file has been generated in the \app\Console\Commands directory

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class Check extends Command
{
  /**
   * The name and signature of the console command.
   *
   * @var string
   */
  protected $signature = &#39;command:name&#39;;

  /**
   * The console command description.
   *
   * @var string
   */
  protected $description = &#39;Command description&#39;;

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

  /**
   * Execute the console command.
   *
   * @return mixed
   */
  public function handle()
  {
    //
  }
}

You can change $signature to the command name you want

protected $signature = &#39;check&#39;;

It cannot be called in the console at this time and needs to be registered in Kernel.php.

protected $commands = [
    &#39;App\Console\Commands\Check&#39;
];

You can already use this command in the console

php artisan check

Comment: It seems useless, because php itself can also use CLI commands without the Laravel framework OK.

Related recommendations:

Explain how to customize encryption services in laravel

Exploring how Laravel's middleware is implemented

Laravel optimization of split routing files

The above is the detailed content of Detailed explanation of Laravel's task scheduling console. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn