Laravel调度在Windows中不起作用

时间:2019-10-03 10:52:51

标签: php laravel laravel-scheduler

我正在研究laravel计划一切正常。我的时间表代码如下:

public function handle()
{
    //
    $words = [
        'aberration' => 'a state or condition markedly different from the norm',
        'convivial' => 'occupied with or fond of the pleasures of good company',
        'diaphanous' => 'so thin as to transmit light',
        'elegy' => 'a mournful poem; a lament for the dead',
        'ostensible' => 'appearing as such but not necessarily so'
    ];
    $key = array_rand($words);
    $value = $words[$key];
    $word = new Word;
    $word->word_key = $key;
    $word->word_value = $value;
    $word->save();
    $this->info('Word of the Day saved in table');
}

protected function schedule(Schedule $schedule)
{
    $schedule->command('word:day')->everyMinute();
}

现在,我运行命令 PHP artisan Schedule:运行,它将数据保存在word表中。

现在我的问题是,一分钟后,它不再保存了。。。我已经在google上进行了研究,并尝试了许多引用,但这些方法根本没有用。

我的项目在E驱动器中,路径为 E:/ xammp / htdocs / testtutorials / phpmonitor ,我在命令下运行,但无法正常工作

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
  ----------------------------------------------------------
* * * * * php /E:/xammp/htdocs/testtutorials/phpmonitor/artisan schedule:run >> /dev/null 2>&1

它给了我下面的错误:

  

系统找不到指定的路径。

enter image description here

1 个答案:

答案 0 :(得分:0)

上面的命令是UNIX风格的命令。 Windows在以下方面有所不同:

  1. 路径不是以/开头,而是以驱动器号开头。
  2. /dev/null设备不存在。 Windows等效为nul

因此,将命令更改为以下内容:

php E:\xampp\htdocs\testtutorials\phpmonitor\artisan schedule:run >nul 2>&1