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 = '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 mixed */ public function handle() { // } }
You can change $signature to the command name you want
protected $signature = 'check';
It cannot be called in the console at this time and needs to be registered in Kernel.php.
protected $commands = [ 'App\Console\Commands\Check' ];
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!