我想在 php 5.5 和 laravel 中异步运行一些任务。我用谷歌搜索,发现 laravel 队列可以做这样的事情。我找到了这个链接寻求帮助:https ://laravel.com/docs/5.1/queues 。我已经安装了依赖项:
亚马逊 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 不会异步运行作业。问题是什么。