Laravel crontab -e无法识别 [英] Laravel crontab -e is not recognized

查看:51
本文介绍了Laravel crontab -e无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次设置Cron作业,我无法使其自动计划命令.

所以我有一个命令:

public function handle()
{
    $client = new Client();
$crawler = $client->request('GET', 'http://www.oldham-chronicle.co.uk/news-features');
$crawler->filter('div[id=content]>.homefeature')->each(function ($node, $key) {
    $title = $node->filter('.plain')->text();
    $datepublished = $node->filter('.dateonline')->text();
    $description = $node->filter('.teaser-link')->text();
    $link = $node->filter('a')->link();
    $link_r = $link->getUri();
    $image = $node->filter('img')->image();
    $image_s = $image->getUri();
    $filename = basename($image_s);
    $image_path = ('news-gallery/' . $filename);
    Image::make($image_s)->save(public_path('news-gallery/' . $filename));
    $id = 1+ $key + 1;
    $news = News::where('id', $id)->first();
    // if news is null
    if (!$news) {
        $news = new News();
    }
    $news->title = $title;
    $news->datepublished = $datepublished;
    $news->description = $description;
    $news->link = $link_r;
    $news->image = $image_path;
    $news->save();
});
$crawler->filter('div[id=content]>.teaser-50')->each(function ($node, $key) {
    $title = $node->filter('.plain')->text();
    $datepublished = $node->filter('.dateonline')->text();
    $description = $node->filter('.teaser-link')->text();
    $link = $node->filter('a')->link();
    $link_r = $link->getUri();
    $image = $node->filter('img')->image();
    $image_s = $image->getUri();
    $filename = basename($image_s);
    $image_path = ('news-gallery/' . $filename);
    Image::make($image_s)->save(public_path('news-gallery/' . $filename));
    $id = 1+ $key + 1;
    $news = News::where('id', $id)->first();
    // if news is null
    if (!$news) {
        $news = new News();
    }
    $news->title = $title;
    $news->datepublished = $datepublished;
    $news->description = $description;
    $news->link = $link_r;
    $news->image = $image_path;
    $news->save();
    $this->info('Scraping done succesfully');
});
}

内核文件:

protected $commands = [
    'App\Console\Commands\NewsScrape'
];

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('scrape:news')
             ->hourly();
}

然后转到项目文件夹,键入crontab -e,我得到:

'crontab'不被识别为内部或外部命令, 可操作的程序或批处理文件.

如何解决?请记住,这是我第一次使用它

解决方案

在生产中,您必须设置以下crontab:

文档: https://laravel.com/docs/5.4/scheduling

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

请确保适当地更新/path-to-your-project/.

这将每分钟运行php artisan schedule:run命令,该命令将检查是否需要运行任何调度程序.

我不知道如何为Windows进行设置,但是我建议使用开发环境 Homestead ,它使用 Vagrant 解决方案

In production you must set up the following crontab:

Docs: https://laravel.com/docs/5.4/scheduling

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

Be sure to update /path-to-your-project/ as appropriate.

This will run the php artisan schedule:run command every minute which will check to see if any schedulers need running.

I do not know how to set this up for Windows, however I suggest using the development environment Homestead, which uses Vagrant and Virtual Box. It will provide you with a Ubuntu VM, so you can use crontab.

这篇关于Laravel crontab -e无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆