Home  >  Article  >  Backend Development  >  请问 Laravel 怎么实现一个定时器任务?

请问 Laravel 怎么实现一个定时器任务?

WBOY
WBOYOriginal
2016-06-06 20:46:12879browse

先说一下大概的情况。框架用的是 Laravel,任务队列用的是 Beanstalkd,然后

<code class="lang-php">php artisan queue:listen
</code>

现在我有个爬虫任务需要隔段时间运行一次,爬虫在爬的过程中会往任务队列里加入一些子任务。

下一次爬虫任务,需要等上次爬虫的所有任务都完成之后才能开始。

但爬虫任务所用时间不知道,也没找到方法判断任务队列是否为空。

那我应该如何决定什么时候(或什么条件下)把下一次爬虫任务加入到任务队列呢?

回复内容:

先说一下大概的情况。框架用的是 Laravel,任务队列用的是 Beanstalkd,然后

<code class="lang-php">php artisan queue:listen
</code>

现在我有个爬虫任务需要隔段时间运行一次,爬虫在爬的过程中会往任务队列里加入一些子任务。

下一次爬虫任务,需要等上次爬虫的所有任务都完成之后才能开始。

但爬虫任务所用时间不知道,也没找到方法判断任务队列是否为空。

那我应该如何决定什么时候(或什么条件下)把下一次爬虫任务加入到任务队列呢?

请搜索cron

目前还没想到特别好的解决方案, 有机会可以探讨下

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn