jeudi 30 juin 2016

Laravel 5 Cron doesn't work

I am not sure why cron doesn't for Laravel artisan commands. But when I launch it manually like php artisan my:command it works.

I have put command in Kernel:

protected function schedule(Schedule $schedule)
{
    $schedule->command('my:command')->everyMinute();
}

Also when I run php artisan schedule:run it says: No scheduled commands are ready to run.

Crontab looks like this:

* * * * * php /project/artisan schedule:run

At first I thought maybe cron itself doesn't work, but it executes php files not related to artisan.

I am using PHP7 if it changes anything.


UPDATED (cron artisan commands work, but schedule dont)

Cron command works (log has been saved in storage/app folder)

* * * * * php /project/artisan command:test

Cron schedule doesn't work

* * * * * php /project/artisan schedule:run

test.php

namespace AppConsoleCommands;

use IlluminateConsoleCommand;
use Storage;
use CarbonCarbon;

class test extends Command
{
    protected $signature = 'command:test';

    protected $description = 'Command description';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        Storage::prepend('test.log', Carbon::now());
    }
}

Kernel.php

namespace AppConsole;

use IlluminateConsoleSchedulingSchedule;
use IlluminateFoundationConsoleKernel as ConsoleKernel;

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


    protected function schedule(Schedule $schedule)
    {
        $schedule->command('command:test')->everyMinute();
    }
}

Aucun commentaire:

Enregistrer un commentaire