Laravel 5.4 task scheduler

偶尔善良 提交于 2019-12-12 05:49:24

问题


I have setup scheduler according to the Laravel 5.4 documentation. But it doesn't work.

My cron job is:

* * * * * php public_html/demo/artisan schedule:run 1>> logs/cronlog.txt

app/console/Kernel.php:

class Kernel extends ConsoleKernel
{    
    protected $commands = [Commands\OverdueTasksNotifier::class,];

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('notify:overduetasks')->everyFiveMinutes();
    }

    protected function commands()
    {
        require base_path('routes/console.php');
    }
}

app/Console/Commands/OverdueTasksNotifier.php:

class OverdueTasksNotifier extends Command
{
    protected $signature = 'notify:overduetasks';

    protected $description = 'Sends alerts (email, sms) for un-Ready overdue tasks.';

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

    public function handle()
    {
        echo 'test';
    }
}

and the cronlog.txt has:

    [ErrorException]                         
    Invalid argument supplied for foreach()

Content-type: text/html; charset=UTF-8

and above text repeats every minute.

I ran php artisan list and it lists the added command above which is notify:overduetasks.

Could someone point me where the error is? I use shared hosting (cPanel).

----- UPDATE -----

debug enabled and the laravel.log is:

[2017-04-29 21:02:02] local.ERROR: exception 'ErrorException' with message 'Invalid argument supplied for foreach()' in /home/serverhostcom/public_html/demo/vendor/symfony/console/Input/ArgvInput.php:284
Stack trace:
#0 /home/serverhostcom/public_html/demo/vendor/symfony/console/Input/ArgvInput.php(284): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Invalid argumen...', '/home/serverhos...', 284, Array)
#1 /home/serverhostcom/public_html/demo/vendor/symfony/console/Application.php(764): Symfony\Component\Console\Input\ArgvInput->hasParameterOption(Array, true)
#2 /home/serverhostcom/public_html/demo/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->configureIO(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /home/serverhostcom/public_html/demo/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(123): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /home/serverhostcom/public_html/demo/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 {main}  

回答1:


I found it was to be a typo in paths to php and artisan.

/usr/local/bin/php /home/[USERNAME]/public_html/artisan schedule:run >> /dev/null 2>&1

Now task scheduler runs properly.



来源:https://stackoverflow.com/questions/43699948/laravel-5-4-task-scheduler

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!