简体   繁体   中英

Laravel 5 schedule issues - php artisan schedule:run works but actual schedule does not

Laravel version 5.7, PHP version 7.2 running on Apache2

The command in my crontab is as follows:

* * * * * php /var/www/dev-site/artisan schedule:run >> /dev/null 2>&1

My kernel is as follows:

<?php

namespace App\Console;

use App\Console\Commands\ImportInvoiceBatch;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    protected $commands = [
        ImportInvoiceBatch::class,
    ];

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('import:invoice-batch')->everyMinute()->withoutOverlapping();
    }

    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

Running my defined command as "php artisan import:invoice-batch" works correctly, and even running "php artisan schedule:run" recognizes everything and runs the task as expected, but the scheduler is not being executed ever minute as should be happening. Is there anything I am missing? Thanks in advance.

Try to change working directory to app root before running artisan:

* * * * * cd /var/www/dev-site/artisan && php artisan schedule:run >> /dev/null 2>&1

Also you could try to add output path for debuging:

* * * * * cd /var/www/dev-site/artisan && php artisan schedule:run >> /var/log/crontab/artisan.log 2>&1

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