我想在php 5.5和laravel中异步运行一些任务。我用谷歌搜索,发现laravel队列可以做这样的事情。我找到了这个链接以寻求帮助:https://laravel.com/docs/5.1/queues。 我已经安装了依赖项:
Amazon SQS:aws / aws-sdk-php~3.0
Beanstalkd:pda / pheanstalk~3.0
IronMQ:iron-io / iron_mq~2.0 | ~4.0
Redis:predis / predis~1.0
我在laravel中添加了队列表。这是我的Job类
class SearchFromSource extends Job implements SelfHandling{
use InteractsWithQueue, SerializesModels;
private $provider;
private $query;
private $pageToken;
private $parameters;
private $needDetails;
public function __construct()
{
}
public function handle()
{
sleep(5);
}
}
这是我派遣工作的地方:
class SearchController extends Controller{
...
public function prepareResults($query, $page, $ip){
$job = (new SearchFromSource($curVideoProvider,$this->query,$curVideoProvider->getDefaultParameters(),$curPageToken,$curVideoProvider->needDetails()))->onQueue("q1");
$this->dispatch($job);
$job2 = (new SearchFromSource($curVideoProvider,$this->query,$curVideoProvider->getDefaultParameters(),$curPageToken,$curVideoProvider->needDetails()))->onQueue("q2");
$this->dispatch($job2);
}
}
问题是laravel不会异步运行作业。有什么问题。
答案 0 :(得分:1)
QUEUE_DRIVER
(sync,redis,beanstalk等)php artisan queue:listen