【发布时间】:2016-03-14 21:26:32
【问题描述】:
我正在尝试实现队列,但结果不是异步的 我已经应用了以下内容
config/queue.php
'default' => env('QUEUE_DRIVER', 'database'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
]
然后应用以下命令 php工匠队列:表 php工匠迁移
然后运行
php artisan queue:listen
这里是功能
SomethingController.php
$model1 = new \App\Model1;
public function store(){
Log::debug('before dispatch');
$this->dispatch(new SendGiftCommand($model1));
Log::debug('before dispatch');
return true;
}
SendGiftCommand.php
{
Log::debug('handle');
SendGift::SendGiftAgedBased($this->model1);
sleep(4);
Log::debug('SendGiftCommand end');
}
SendGift.php
public static function SendGiftAgedBased(Model1 $model1){
Log::debug('inside SendGiftAgedBased');
}
即使进程已经工作但它不是异步的,它等待命令完成以在控制器中返回响应
我按这个顺序 git 日志
[2015-12-09 16:28:42] local.DEBUG: before dispatch
[2015-12-09 16:28:42] local.DEBUG: handle
[2015-12-09 16:28:42] local.DEBUG: inside SendGiftAgedBased
[2015-12-09 16:28:46] local.DEBUG: SendGiftCommand end
[2015-12-09 16:28:46] local.DEBUG: after dispatch
它应该在 Localhost 上工作吗?
【问题讨论】:
标签: php laravel asynchronous laravel-5 queue