Help us understand the problem. What is going on with this article?

[Laravel]タスクスケジュール設定Cronインストールから

More than 3 years have passed since last update.

cronインストール

動作確認

/etc/rc.d/init.d/crond status
  • インストールされているかを確認

インストール

yum install -y crontabs vixie-cron
  • インストール確認
/etc/rc.d/init.d/crond status

cron起動

/etc/rc.d/init.d/crond start

自動起動の確認

chkconfig --list crond

サービスを追加

chkconfig --add crond

crontabにLaravelのタスクエントリを追加

crontab -e
* * * * * php [プロジェクトのパス]/artisan schedule:run >> /dev/null 2>&1
  • 以上でcronが起動して毎分Laravelのタスクスケジュールが起動します
  • ログを確認する時は「/var/log/cron」から確認できます。

スケジュール追加

  • /app/Console/Kernel.phpを編集
    protected $commands = [
        \App\Console\Commands\Inspire::class,
        \App\Console\Commands\Hoge::class,  // 追加
    ];


    protected function schedule(Schedule $schedule)
    {
        $schedule->command('inspire')->hourly();
        $schedule->command('hoge')-> everyFiveMinutes();  // 5分毎に実行
    }
  • /app/Console/Commands/hoge.phpを作成
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;



class Hoge extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'hoge';

    /**
     * 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()
    {
        Storage::disk('local')->put(date("Ymd_His").'.txt', 'message');
    }
}
  • これで5分毎にログを記録するスケジュールが作成されます
meso_
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした