gpt4 book ai didi

cron - Laravel 5.2 Cron 不适用于 centos

转载 作者:行者123 更新时间:2023-12-04 21:35:22 25 4
gpt4 key购买 nike

当我尝试在 localhost(php 版本:PHP 5.6.4-4ubuntu6.4 (cli))上运行 Task Schedular 时,它运行良好。

定时任务表

* * * * * php /home/aishatest/public_html/Aisha/Aisha/artisan schedule:run >> /dev/null 2>&1

应用程序/控制台/Kernel.php
<?php

namespace App\Console;

use App\Console\Commands\CheckOutfitAvailibilityCommand;
use App\Http\Controllers\OutfitCronController;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
// Commands\Inspire::class,
CheckOutfitAvailibilityCommand::class
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
\Log::error("Kernel");
//$schedule->command('inspire')
// ->everyMinute();
$schedule->command('CheckOutfitCommand')->cron('* * * * *');
}
}

应用程序/控制台/命令/CheckOutfitAvailibilityCommand.php
<?php

namespace App\Console\Commands;

use App\Http\Controllers\OutfitCronController;
use Illuminate\Console\Command;

class CheckOutfitAvailibilityCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
private $outfitCronController;
protected $signature = 'CheckOutfitCommand';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct(OutfitCronController $outfitCronController)
{

parent::__construct();
$this->outfitCronController = $outfitCronController;
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
\Log::error("command handle");
$this->outfitCronController->checkOutfitAvailability();
}
}

但是当我尝试在 CentOs 服务器(php 版本 PHP 5.6.26 (cli))上运行时,它给出了如下错误

./storage/logs/laravel.log
[2016-09-22 05:54:02] local.ERROR: Kernel  
[2016-09-22 05:54:05] local.ERROR: exception 'ErrorException' with message 'Invalid argument supplied for foreach()' in /home/aishatest/public_html/Aisha/Aisha/vendor/symfony/console/Input/ArgvInput.php:281
Stack trace:
#0 /home/aishatest/public_html/Aisha/Aisha/vendor/symfony/console/Input/ArgvInput.php(281): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Invalid argumen...', '/home/aishatest...', 281, Array)
#1 /home/aishatest/public_html/Aisha/Aisha/vendor/symfony/console/Application.php(743): Symfony\Component\Console\Input\ArgvInput->hasParameterOption(Array, true)
#2 /home/aishatest/public_html/Aisha/Aisha/vendor/symfony/console/Application.php(114): Symfony\Component\Console\Application->configureIO(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /home/aishatest/public_html/Aisha/Aisha/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/aishatest/public_html/Aisha/Aisha/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 {main}

如果我尝试在终端中手动运行以下命令,那么它也可以完美运行。
php /home/aishatest/public_html/Aisha/Aisha/artisan schedule:run

我试图找到解决方案,但找不到任何解决方案。

最佳答案

使用php的绝对路径

/usr/local/bin/php/path/to/artisan schedule:run >>/dev/null 2>&1

我有同样的问题。内核 schedule() 函数中的 cron 作业有效,但任何时候我尝试调用控制台命令时,它都会抛出异常。

关于cron - Laravel 5.2 Cron 不适用于 centos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39631516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com