Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

leelanarasimha's avatar

Laravel artisan Schedule Run getting Invalid foreach

I am running cron job that need to send update for me daily at midnight.

It is throwing exception in the log.

[2015-11-15 04:38:01] local.ERROR: exception 'ErrorException' with message 'Invalid argument supplied for foreach()' in /home/festsama/public_html/livesite/live/vendor/symfony/console/Input/ArgvInput.php:287

Please can anyone help me any one how to solve this.

My cron command in shared hosting

php /home/festsama/public_html/livesite/live/artisan schedule:run

0 likes
7 replies
bobbybouwmann's avatar

Show your code! We can't help you without knowing the code you run ;)

leelanarasimha's avatar

Sure @bobbybouwmann

In console/commands/dailyupdate.php

class dailyupdate extends Command
{
    protected $signature = 'dailyupdates';
    public function __construct()
        {
            parent::__construct();
        }
     public function fire() 
    {
            $this->info('Daily Updates sent successfully');
        }
    public function handle()
        {
            $data['popular'] = Fest::orderBy('fest_popular_order', 'ASC')->where('status', 1)->whereNotNull('fest_popular_order')->take(3)->get();
            $users = User::where('status', 1)->get();
            if (isset($users)) {
                    foreach ($users as $user) {
                        \Mail::send('mails.dailyupdate', $data, function ($message) use ($user) {
                            $message->from('contact@festsamachar.com', 'Fest Samachar');
                            $message->to($user->email_id);
                            $message->subject('Hi ' . $user->name . '.. Popular Fests in Fest Samachar');
                    });
                }
        }

In commands/kernel.php

protected function schedule(Schedule $schedule) { $schedule->command('dailyupdates') ->daily(); }

My cron command in shared hosting:

php /home/festsama/public_html/livesite/live/artisan schedule:run

in laravel.log the error showing as

#0 /home/festsama/public_html/livesite/live/vendor/symfony/console/Input/ArgvInput.php(287): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Invalid argumen...', '/home/festsama/...', 287, Array) #1 /home/festsama/public_html/livesite/live/vendor/symfony/console/Application.php(827): Symfony\Component\Console\Input\ArgvInput->hasParameterOption(Array) #2 /home/festsama/public_html/livesite/live/vendor/symfony/console/Application.php(123): Symfony\Component\Console\Application->configureIO(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #3 /home/festsama/public_html/livesite/live/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #4 /home/festsama/public_html/livesite/live/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

leelanarasimha's avatar
Level 8

After a long search and research

I got the problem solved.

register_argc_argv is set to off in php.ini

we have to make register_argc_argv should be set to true.

derekmcwhinnie's avatar

I too have hosted a Laravel app on a shared host. I too have had the same problems with the scheduler. My solution does not agree with the answers above.

Firstly, "register_argc_argv " set to ON or OFF made absolutely no difference to the scheduler. It still failed with a "'ErrorException - Invalid argument supplied for foreach()".

The solution (for me) appears to be the way the cron job is set up. The Laravel documentation states that the cron job should be set up thus.....

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

but for me this did not work. My solution (after a lot of googling...) was to use this instead

* * * * * php-cli -q /home/path/to/artisan schedule:run >> /dev/null 2>&1

very similar but not identical.

The "1" after the "schedule:run" causes the Symphony Console component to raise a "Too many arguments exception". I removed the "1" and the error changed so it was having an effect.

The main issue seems to be the use of Command Line PHP ("php-cli") instead of plain old "php". After this change was implemented everything just started to work as expected.

7 likes
framgia's avatar

I met the same issue. The reason is server not default php-cli, so it's not run cron Please change it to: " * * * * * /usr/bin/php-cli /path/to/project/artisan schedule:run >> /dev/null 2>&1 "

etheco's avatar

I had the same issue even though register_argc seemed to be enabled on the ini, I had to force it on the php-cli run

This was under cloudlinux

* * * * * cd /home/site/public_html && php -d register_argc_argv=On artisan schedule:run >> /dev/null 2>&1

Please or to participate in this conversation.