Laravel 5.6 Cron Job not Working on Shared Hosting Good day,
I have a Job that I am scheduling every minute to send some mails.
When I run
php artisan schedule:run
via Putty it works. But when setting up via cron job it simple does not trigger my Job.
This is my cron job command:
cd /home/user/laravel_dir && php artisan schedule:run >> /dev/null 2>&1
Please assist me. I am using HawkHost shared hosting.
Also when running that exact script via Terminal (cpanel) it works 100%.
But just not via Cron job command.
In my Laravel log file I found the following error:
[2018-10-01 11:07:02] local.ERROR: Invalid argument supplied for foreach() {"exception":"[object] (ErrorException(code: 0): Invalid argument supplied for foreach() at /home/handbrak/laravel_getlicense.co.za/vendor/symfony/console/Input/ArgvInput.php:259)
[stacktrace]
#0 /home/handbrak/laravel_getlicense.co.za/vendor/symfony/console/Input/ArgvInput.php(259): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Invalid argumen...', '/home/handbrak/...', 259, Array)
#1 /home/handbrak/laravel_getlicense.co.za/vendor/symfony/console/Application.php(935): Symfony\Component\Console\Input\ArgvInput->getFirstArgument()
#2 /home/handbrak/laravel_getlicense.co.za/vendor/laravel/framework/src/Illuminate/Console/Application.php(80): Symfony\Component\Console\Application->getCommandName(Object(Symfony\Component\Console\Input\ArgvInput))
#3 /home/handbrak/laravel_getlicense.co.za/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /home/handbrak/laravel_getlicense.co.za/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 {main}
"}
Thanks @pardeepkumar but that is exactly what i did. Except I do not have a custom Artisan command. I am using the existing
php artisan schedule:run
command.
Please :) I need help here....
Have you asked the hosting company? Maybe you need to specify the user the cron job is running under, or provide a full path to php.
When googling the error most articles talk about the php variabel "register_argc_argv" which I have now set to ON via my .htaccess file.
Yes I talked to hosting company and they also see the same error message that I am getting in my Laravel log file.
If you don't specify the path to the PHP version you want you may end up with the wrong version. I have known hosts with multiple versions of php installed.
Your cron command should be the full path to php and the full path to your project, eg;
* * * * * /usr/bin/php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1
Okay thanks got it working. Had to include path the php as in such:
cd path\to\laravel_app && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
@Sven0188 Thank you, it works for me, I'm using shared hosting (A2 Hosting).
the solution for me was /usr/local/bin/php
This still did not work for me
Cron: * * * * * php /home/something.com/artisan schedule:run >> /dev/null 2>&1
Laravel: 5.5
PHP: 7.2
Please help
@shahidkarimi You need to find the path for php and specify it in the command
Please sign in or create an account to participate in this conversation.