Php Laravel cron作业未运行
这是我第一次设置Cron作业,我无法让它自动安排命令 所以我有一个命令:Php Laravel cron作业未运行,php,laravel,laravel-5,cron,Php,Laravel,Laravel 5,Cron,这是我第一次设置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')->e
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('some@email);
}
我可以以php artisan scrape:news的形式手动运行它,但当我将其添加到crontab-e时,它仍然可以工作:
* * * * * php /var/www/fyproject/ schedule:run >> /dev/null 2>&1
Cronjob从未运行过,任何帮助 该命令需要通过
artisan
调用,因此您必须记住将其添加到调用中:
使用:
需要通过
artisan
调用该命令,因此必须记住在调用中添加该命令:
使用:
应该是
php/var/www/fyproject/artisan schedule:run
Haha nice error把它作为答案,我会标记它;)不是开玩笑,我第一次尝试设置它时也犯了完全相同的错误。一个提醒。。。您可以转到终端,然后键入该命令。在我的例子中,我的laravel.log有错误的权限,我可以通过这种方式调试它应该是php/var/www/fyproject/artisan schedule:run
Haha很好的错误,把它作为一个答案,我会标记它;)不是开玩笑,我第一次尝试设置它时也犯了完全相同的错误。一个提醒。。。您可以转到终端,然后键入该命令。在我的情况下,我的laravel.log有错误的权限,我可以通过这种方式调试如何检查这是否有效,请帮助@apokryfos检查这是否有效,请帮助@apokryfos
crontab -e * * * * * php /var/www/fyproject/artisan schedule:run >> /dev/null 2>&1