首頁  >  文章  >  後端開發  >  詳解Laravel的任務調度console

詳解Laravel的任務調度console

*文
*文原創
2018-01-03 13:00:322648瀏覽

本文主要給大家簡單介紹了Laravel中任務調度console使用方法,並附上一個簡單的範例,希望對大家學習使用console能夠有所幫助。

適用場景:分析資料(日誌)

php artisan make:console 你的命令类名

範例:

php artisan make:console Check

在\app\Console\Commands目錄下已產生一個Check.php檔案

<?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()
  {
    //
  }
}

你可以把$signature改為你要的指令名稱

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

此時還不能在控制台中調用,需要在Kernel.php中註冊。

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

你已經可以在控制台中使用這個指令了

php artisan check

點評:似乎也沒啥用,因為php本身也可以不用Laravel框架來使用CLI指令行。

相關推薦:

講解如何在laravel中自訂加密服務

探究Laravel的中間件是如何實現的

#Laravel優化分割路由檔案

#########Laravel最佳化之分割路由檔案#########

以上是詳解Laravel的任務調度console的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn