简体   繁体   中英

Set schedule cron job in Laravel

I have set a cron job

* * * * * php /var/www/html/laravel schedule:run 1>> /var/www/html/log_laravel 2>&1

This is what I have set in app\\console\\Kernel.php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Http\Controllers\DataController;

class Kernel extends ConsoleKernel
{

    protected $commands = [
    ];


    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {
            DataController::get_data();
        })->everyMinute();
    }


}

Is that it? In docs there isn't anything else but this is not working. DataController@get_data should perfom some updates in database (I can also call this manually by going to http//www.site.com/public/data/get_data . How can I debug this? I don't have anything in log file in storage/logs and my log_laravel for Cron job is empty.

You need to reference the path to artisan.php script:

* * * * * php /var/www/html/laravel/artisan schedule:run 1>> /var/www/html/log_laravel 2>&1

I do not recommend writing output to any logs, this will run every minute, and will kill your disk space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM