Laravel中任务调度console使用方法小结

适用场景:分析数据(日志)

PHP;gutter:true;"> PHP artisan make:console 你的命令类名

示例:

PHP;gutter:true;"> PHP artisan make:console Check

在\app\Console\Commands目录下已生成一个Check.PHP文件

PHP;gutter:true;"> 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()
    {
    //
    }
    }

你可以把$signature改为你要的命令名称

PHP;gutter:true;"> protected $signature = 'check';

此时还不能在控制台中调用,需要在Kernel.PHP注册

PHP;gutter:true;"> protected $commands = [ 'App\Console\Commands\Check' ];

你已经可以在控制台中使用这个命令了

PHP artisan check

点评:似乎也没啥用,因为PHP本身也可以不用Laravel框架来使用CLI命令行。

相关文章

[laravel] laravel的数据库配置 找到程序目录结构下.env文件 配置基本的数据库连接信息 DB_HOST=127.0....
[Laravel] Laravel的基本HTTP路由 使用Laravel的基本路由,实现get请求响应,找到文件app/Http/routes....
如果说laravel框架的核心是什么,那么无疑是服务容器。理解服务容器的概念,对于我们使用laravel太重要...
网上有很多解析laravel中间件的实现原理,但是不知道有没有读者在读的时候不明白,作者是怎么想到要用a...
laraveli添加一个或多个用户表,以admin为例。 部分文件内容可能需要根据实际情况修改 创建一个Admin模...
TL;DR: 本文介绍 Laravel 的 FastExcel 组件,文中会对 PHP generators 速览,并给出如何在节约内存的同...