Fix: Laravel scheduled tasks exception

So I just added a little scheduled tasks to one of my applications which was hosted on a shared environment and I realized that the task was not being executed at all.

running the php command from the shell was working and it was not giving me any clue on what the problem could be.

So as the solution I removed the forwarding to dev/null from the ending of my cron task command, after looking at the output I realized that the following exception was causing the Laravel scheduled tasks not to work.

  [ErrorException]
  Invalid argument supplied for foreach()

This issue appears when you have ‘register_argc_argv‘ disabled in your php configuration or maybe at least for croncli. the quickest way to solve this is to make a bit of changes to the cron command that laravel provided in the documentations and turn it into:

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

Basically adding ‘-d register_argc_argv=On‘ will tell php to consider this setting as on and continue executing the script.

Edit: for your own sake use the full path to your PHP. if you do not do that Laravel will pick some general path and it might not be compatible with the environment that you are hosting your application at.

Hope this post helps some of you out.

Incoming search terms:

  • laravel schedule mutex cleanup fix
  • laravel scheduleg task error handling

Join the Conversation

4 Comments

  1. Thank you!! This was my issue.

    I would also note that using the -d option is a better solution than updating the php.ini directly since 1) sometimes in shared hosting situations the php.ini is not accessible. And, even if it is, 2) setting the register_argc_argv directive to “On” makes the “auto_globals_jit” directive ineffective.

Leave a comment

Leave a Reply