Laravel 调度程序作业中为 foreach() 提供的参数无效

Invalid argument supplied for foreach() in Laravel Schedular Job

我在 Laravel 5.8Schedular 一起工作。设置 CommandsCommand Kernal 后,我得到的错误是,

Invalid argument supplied for foreach() at /home/SERVER_USER_NAME/public_html/vendor/symfony/console/Input/ArgvInput.php:261)

这是Kernal方法,

protected $commands = [
    Commands\OfferMonitor::class,
    Commands\RankingCommand::class,
    Commands\CreditCycle::class,
];

protected function schedule(Schedule $schedule)
{
    $schedule->command('KG:OfferMonitor')->dailyAt('01:00');
    $schedule->command('KG:UpdateRanks')->everyTenMinutes();
    $schedule->command('KG:CreditCycle')->dailyAt('00:00');
}

这是我在生产服务器上的 Laravel Cron Job 运行,

我认为 cron 作业本身会引发错误,我使用的是 php 二进制而不是 php-cli。它会导致错误吗?如果是,这个问题的解决方法是什么?

这是来自 Laravel、

的完整错误日志和堆栈跟踪
Invalid argument supplied for foreach() {"exception":"[object] (ErrorException(code: 0): Invalid argument supplied for foreach() at /home/SERVER_USER_NAME/public_html/vendor/symfony/console/Input/ArgvInput.php:261)
[stacktrace]
#0 /home/SERVER_USER_NAME/public_html/vendor/symfony/console/Input/ArgvInput.php(261): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Invalid argumen...', '/home/SERVER_USER_NAME...', 261, Array)
#1 /home/SERVER_USER_NAME/public_html/vendor/symfony/console/Application.php(970): Symfony\Component\Console\Input\ArgvInput->getFirstArgument()
#2 /home/SERVER_USER_NAME/public_html/vendor/laravel/framework/src/Illuminate/Console/Application.php(81): Symfony\Component\Console\Application->getCommandName(Object(Symfony\Component\Console\Input\ArgvInput))
#3 /home/SERVER_USER_NAME/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(133): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /home/SERVER_USER_NAME/public_html/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 {main}
"}

Note: The Commands scheduled in Kernal.php is running properly when I use them with artisan from terminal, so there is no issue about command.

尝试将 cron 命令设置为这样

/usr/local/bin/php register_argc_argv=1 artisan schedule:run >> /dev/null 2>&1

尝试使用 -d 标志将 register_argc_argv(ini 配置变量)设置为 1

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

同时在您的 /path-to-your-project 中使用

创建 php.ini 文件
register_argc_argv = On

在您的项目根目录中创建一个 php.ini 文件

eg: /public_html/myproject

在您已经创建的 php.ini 文件中添加 register_argc_argv = On

就这些了

这条命令行对我有用,希望对你有所帮助。

/usr/local/bin/php ~/public_html/artisan reminder:users >> /dev/null 2>&1