1

With laravel schedule I have problem. schedule runs but command not working. here is example.I send mail from schedule on every minute and also want to run command on every minute to test it. command not working. I did't get email from command(with text "command executed").What I am doing wrong? Please help.

Kernel.php

class Kernel extends ConsoleKernel {

    protected $commands = [
        'App\Console\Commands\myCustomCommand'
    ];

    protected function schedule(Schedule $schedule) {

        //this works
        sendMailFunction('someone@gmail.com', 'test mail', 'schedule executed'); 

        //this is not working
        $schedule->command('command:myCustomCommand')->cron('* * * * *')
    }

}

Command

class myCustomCommand extends Command {


    protected $name = 'command:myCustomCommand';


    protected $description = 'some description';


    public function handle() {
        sendMailFunction('someone@gmail.com', 'test mail', 'command executed');
    }

}
gogagubi
  • 965
  • 1
  • 15
  • 36
  • Maybe you should test yout command from command line first? What error does it return? – Alexey Mezenin Feb 28 '16 at 10:29
  • there are no errors. from command line it works. i think cron() function is not works. I also tried everyMinute() but still no result. I have no idea why it not works – gogagubi Feb 28 '16 at 10:38
  • 1
    Did you run this on your server: `* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1` to enable Laravel scheduler? – Alexey Mezenin Feb 28 '16 at 10:42
  • yes scheduler working. because I got emails from schedule in every minute with text "schedule executed" – gogagubi Feb 28 '16 at 10:51
  • 1
    Well, it's really strange. Are there any schedule or sending mails related errors in `/storage/laravel.log`? – Alexey Mezenin Feb 28 '16 at 10:53
  • Also maybe you want to try to stop cron and rerun it so it output errors and messages into some log file, like `* * * * * php /path/to/artisan schedule:run >> /home/sched.log 2>&1` and after that use `try...catch` constructure to output any catched exceptions. – Alexey Mezenin Feb 28 '16 at 11:04
  • Oh yes. I found reason. In logs I have error "exec() has been disabled for security reasons". Thanks for your comments. – gogagubi Feb 28 '16 at 18:26
  • It may seemed the schedule works, but actually not. Refer to [laravel cannot run scheduled command, while queue:listen run schedule() periodically](https://stackoverflow.com/q/47548220/6521116) – LF00 Dec 01 '17 at 07:05
  • did you checked your php artisan list? to see if your command "command:myCustomCommand" exist or not!! – Mhmd Oct 21 '19 at 13:09

1 Answers1

0

in localhost :php artisan schedule:run

in host :* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

You have to see what it is or Introduce your controller in kernel.php

Netwons
  • 1,170
  • 11
  • 14