第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

無涯教程:Laravel 8 - 任務調(diào)度介紹

標簽:
laravel

本教程将为您提供有关如何在laravel 8中创建cron作业的简单示例。

步骤1:安装Laravel 8

在此步骤中,如果您还没有laravel 8应用程序设置,那么我们必须获取最新的laravel 8应用程序。

composer create-project --prefer-dist laravel/laravel blog

步骤2:创建命令

在这一步中,我们需要创建我们的自定义命令。自定义命令将与任务调度scron作业一起执行。

php artisan make:command DemoCron --command=demo:cron


现在对命令文件进行一些更改。

app/Console/Commands/DemoCron.php

<?php
   
namespace App\Console\Commands;
   
use Illuminate\Console\Command;
   
class DemoCron extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'demo:cron';
    
    /**
     * 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()
    {
        \Log::info("Cron is working fine!");
     
        /*
           Write your database logic we bellow:
           Item::create(['name'=>'hello new']);
        */
    }
}

步骤3:注册为任务调度程序

在此步骤中,需要在Kernel.php文件上定义我们执行时间的命令:

->everyMinute();Run the task every minute
->everyFiveMinutes();Run the task every five minutes
->everyTenMinutes();Run the task every ten minutes
->everyFifteenMinutes();Run the task every fifteen minutes
->everyThirtyMinutes();Run the task every thirty minutes
->hourly();Run the task every hour
->hourlyAt(17);Run the task every hour at 17 mins past the hour
->daily();Run the task every day at midnight
->dailyAt(’13:00′);Run the task every day at 13:00
->twiceDaily(1, 13);Run the task daily at 1:00 & 13:00
->weekly();Run the task every week
->weeklyOn(1, ‘8:00’);Run the task every week on Tuesday at 8:00
->monthly();Run the task every month
->monthlyOn(4, ’15:00′);Run the task every month on the 4th at 15:00
->quarterly();Run the task every quarter
->yearly();Run the task every year
->timezone(‘America/New_York’);Set the timezone

app/Console/Kernel.php

<?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 = [
        Commands\DemoCron::class,
    ];
     
    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('demo:cron')
                 ->everyMinute();
    }
     
    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');
     
        require base_path('routes/console.php');
    }
}

步骤4:运行scheduler命令以进行测试

现在我们已准备好运行我们的Cron,因此您可以使用以下命令手动检查您的Cron命令。

php artisan schedule:run

运行以上命令后,您可以检查我们已打印一些文本的日志文件。

storage/logs/laravel.php

[2019-04-24 03:46:42] local.INFO: Cron is working fine!  
[2019-04-24 03:46:52] local.INFO: Cron is working fine!  
[2019-04-24 03:46:55] local.INFO: Cron is working fine!

最后,您可以在调度任务上管理此命令,您必须向服务器的Crontab文件添加一个记录:

* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1
   
OR
  
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1


點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
PHP開發(fā)工程師
手記
粉絲
8
獲贊與收藏
17

關(guān)注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消