3

I'm working with Schedular in Laravel 5.8. after setting up the Commands and Command Kernal I'm getting the error as,

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

Here is the Kernal methods,

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');
}

Here is my Laravel Cron Job running on production server, Cron Job

I think the cron job itself throws an error, I'm using php binary instead of php-cli. Does it caused error? if yes, what's the workaround to this issue?

Here is the complete error log and stacktrace from 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.

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81

5 Answers5

3

Try setting the cron command as this

/usr/local/bin/php register_argc_argv=1 artisan schedule:run >> /dev/null 2>&1
N69S
  • 16,110
  • 3
  • 22
  • 36
2

Try setting register_argc_argv (ini config var) as 1 using -d flag

php -d register_argc_argv=1 artisan schedule:run >> /dev/null 2>&1
Ameer Hamza
  • 108
  • 13
0
* * * * * cd /path-to-your-project && php -d register_argc_argv=1 artisan schedule:run >> /dev/null 2>&1

Also create php.ini file in your /path-to-your-project with

register_argc_argv = On
Maulik Bhatt
  • 35
  • 1
  • 7
0

Create a php.ini file in your project root

eg: /public_html/myproject

Add register_argc_argv = On in your php.ini file that you already created

Thats all

Akeel ahamed
  • 877
  • 11
  • 11
0

This command line worked for me, hope it helps.

/usr/local/bin/php ~/public_html/artisan reminder:users >> /dev/null 2>&1
Santiago Vasquez
  • 149
  • 1
  • 10