laravel寫crontab

簡要描述:

  • laravel寫crontab

artisan命令:

  • php artisan make:command DealTheme

app/Console/Commands下就會看到DealTheme.php:

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:deal_theme';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'DealTheme';
  • 需要執(zhí)行的方法寫在handle中:
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
       
    }

在app/Console/Kernel中注冊路由:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        \App\Console\Commands\DealTheme::class
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
          //  設置每秒執(zhí)行一次
         $schedule->command('command:deal_theme')->everyMinute();
    }

    /**
     * Register the Closure based commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        require base_path('routes/console.php');
    }
}

在linux的crontab -e中插入:

* * * * * /usr/lnmp/php/bin/php /www/artisan schedule:run >> /dev/null 2>&1

注意:

  • laravel的command需要關閉proc_open、proc_get_status函數(shù)禁用。
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容