Asynchronous lines in Laravel

I am trying to implement Queuing, but the result is not async And I applied the following

config/queue.php
'default' => env('QUEUE_DRIVER', 'database'),
    'connections' => [

    'sync' => [
        'driver' => 'sync',
    ],

    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'expire' => 60,
    ],
   ] 

and then applied the following commands: php artisan queue: table Migrate php-artisan table

and then run

php artisan queue:listen

and here is the functionality

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');
} 

even the process worked, but it is not asynchronous, and it waits for the completion of the command to return a response in the controller

And I git magazines in that order

 [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 

should it work with localhost?

+4
source share
3 answers

I had the same problem as jobs that are not asynchronous and this worked for me:

  • Modify .env and change the QUEUE_DRIVER parameter : config/queue.php )
  • .
+4

, ​​ , Illuminate\Contracts\Queue\ShouldQueue - , .

: http://laravel.com/docs/5.1/queues#writing-job-classes

+2

:

   php artisan make:job SendGiftCommand --queued    

:

 https://laravel.com/docs/5.1/queues#writing-job-classes

:

    $processGift = new sendGiftCommand($model1);
    $this->dispatch($processGift);

. : , .

0

Source: https://habr.com/ru/post/1619219/


All Articles