0
這是我第一次設置Cron作業,但無法自動安排命令。Laravel 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')
->everyMinutes();
->emailOutputTo('[email protected]);
}
我可以手動運行它作爲PHP工匠刮:新聞和它的作品,但是當我將它添加到的crontab - e:
* * * * * php /var/www/fyproject/ schedule:run >> /dev/null 2>&1
Cronjob永遠不會運行,任何幫助!
它應該是'PHP /無功/網絡/ fyproject /工匠時間表:運行' – apokryfos
哈哈很好的錯誤把它作爲答案,我會標記它;) – Przemek
沒有笑話,我第一次嘗試設置它也犯了完全相同的錯誤。 – apokryfos