我已经根据Laravel 5.4文档安装了调度程序.但这不起作用.
I have setup scheduler according to the Laravel 5.4 documentation. But it doesn't work.
我的日常工作是:
* * * * * php public_html/demo/artisan schedule:run 1>> logs/cronlog.txtapp/console/ Kernel.php :
app/console/Kernel.php:
class Kernel extends ConsoleKernel { protected $commands = [Commands\OverdueTasksNotifier::class,]; protected function schedule(Schedule $schedule) { $schedule->command('notify:overduetasks')->everyFiveMinutes(); } protected function commands() { require base_path('routes/console.php'); } }app/Console/Commands/ OverdueTasksNotifier.php :
app/Console/Commands/OverdueTasksNotifier.php:
class OverdueTasksNotifier extends Command { protected $signature = 'notify:overduetasks'; protected $description = 'Sends alerts (email, sms) for un-Ready overdue tasks.'; public function __construct() { parent::__construct(); } public function handle() { echo 'test'; } }和 cronlog.txt 具有:
[ErrorException] Invalid argument supplied for foreach() Content-type: text/html; charset=UTF-8及以上文字每分钟重复一次.
and above text repeats every minute.
我运行了php artisan list,它列出了添加的命令,上面是notify:overduetasks.
I ran php artisan list and it lists the added command above which is notify:overduetasks.
有人可以指出我的错误所在吗?我使用共享主机(cPanel).
Could someone point me where the error is? I use shared hosting (cPanel).
-----更新-----
debug且laravel.log为:
debug enabled and the laravel.log is:
[2017-04-29 21:02:02] local.ERROR: exception 'ErrorException' with message 'Invalid argument supplied for foreach()' in /home/serverhostcom/public_html/demo/vendor/symfony/console/Input/ArgvInput.php:284 Stack trace: #0 /home/serverhostcom/public_html/demo/vendor/symfony/console/Input/ArgvInput.php(284): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Invalid argumen...', '/home/serverhos...', 284, Array) #1 /home/serverhostcom/public_html/demo/vendor/symfony/console/Application.php(764): Symfony\Component\Console\Input\ArgvInput->hasParameterOption(Array, true) #2 /home/serverhostcom/public_html/demo/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->configureIO(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #3 /home/serverhostcom/public_html/demo/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(123): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #4 /home/serverhostcom/public_html/demo/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #5 {main}推荐答案
我发现这是通向php和artisan的错字.
I found it was to be a typo in paths to php and artisan.
/usr/local/bin/php /home/[USERNAME]/public_html/artisan schedule:run >> /dev/null 2>&1现在任务计划程序可以正常运行.
Now task scheduler runs properly.
更多推荐
Laravel 5.4任务计划程序
发布评论