简体   繁体   中英

Command schedule in Laravel

I'm trying to a execute scheduled command every five minutes in background. I use this code

protected function schedule(Schedule $schedule)
    {

        $schedule->command('read:mail')->cron('*/1 * * * * *')->sendOutputTo(storage_path().'/logs/output.txt')->withoutOverlapping();

    } 

I suppose that this code is fine, when i use php artisan scheduler:run command works, but doesn't work every five minutes in background. ¿Any idea?

If you want to use the scheduler you need to add a Cron entry in your server, this line will call the Laravel scheduler every minute and do the tasks.

There is the line you need to add to your Crontab:

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

In case you are using Ubuntu to edit your crontab you can run crontab -e and add the line on the bottom.

You can read more on the official docs about Scheduling .

If you are using Windows you can follow this Stackoverflow question to add a task to the Windows task scheduler.

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