use*_*451 7 php queue asynchronous laravel laravel-5
我正在尝试实现排队,但是结果不是异步的,并且我已经应用了以下内容
config/queue.php
'default' => env('QUEUE_DRIVER', 'database'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
]
Run Code Online (Sandbox Code Playgroud)
然后应用以下命令php artisan queue:table php artisan migration
然后运行
php artisan queue:listen
Run Code Online (Sandbox Code Playgroud)
这是功能
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');
}
Run Code Online (Sandbox Code Playgroud)
即使该进程已运行,但仍未同步,它会等待命令完成以返回控制器中的响应
我按此顺序搅拌日志
[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
Run Code Online (Sandbox Code Playgroud)
它应该在Localhost上工作吗?
为了使作业排队,作业类需要实现Illuminate\Contracts\Queue\ShouldQueue接口 - 确保它对于您的类来说是正确的。
您可以在此处找到有关排队作业的更多信息:http://laravel.com/docs/5.1/queues#writing-job-classes
归档时间: |
|
查看次数: |
5721 次 |
最近记录: |