Laravel Scheduler只运行一次

时间:2017-08-17 01:33:36

标签: php laravel cron scheduler jobs

我正在尝试每分钟运行一次控制器功能来更新服务器的状态,但我的调度程序只在更新表中的所有行后才运行一次。这是我第一次在Laravel中使用任务调度程序。我尝试在cmd上运行它,它说运行预定命令:关闭并且在所有表更新后任务停止。

//My Controller function to be called

public function updateServerScheduler()
{
  $servers = Server::all();
  ini_set('max_execution_time', 300);

  foreach ($servers as $server)
  {
      //$server->firewall = @fsockopen($server->ip, 80, $errno, $errstr, 30);

      exec("ping -w 60 " . $server->ip, $output, $result);

      if($result != 0)
      {
        $server->status = 0;
        $server->latency = "None";
      }
      else
      {
        $server->status = 1;
        $server->latency = $this->pingDomain($server->ip);
      }

      $server->last_update = date('Y-m-d H:i:s');
      $server->save();
  }
}


//My Kernel.php

namespace App\Console;
use App\Http\Controllers\HomeController;
use Server;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
     protected $commands = [
       //
     ];
     protected function schedule(Schedule $schedule)
     {

            $schedule->call(function () {
              $hc = new HomeController();
              $hc->updateServerScheduler();
            })->everyMinute();
     }

     protected function commands()
     {
        require base_path('routes/console.php');
     }
}

1 个答案:

答案 0 :(得分:0)

创建运行调度程序的命令并将其添加到内核文件中。 恩。 $时刻表>命令( '试验') - > everyMinute();