Blogger Information
Blog 7
fans 0
comment 0
visits 15447
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Laravel Job (Laravel - 队列)
冷雨画桥
Original
4929 people have browsed it

Laravel-Job

配置修改

  1. ./config/queue.php
  2. 'default' => env('QUEUE_DRIVER', 'sync'),
  3. .env
  4. QUEUE_DRIVER=redis

队列

  1. php artisan make:job TestRedis
  2. TestRedis.php
  3. prodected $data;
  4. public $tries = 3;//最大重试次数
  5. public $timeout = 90;//单个任务最大处理时间
  6. public function __construct($data)
  7. {
  8. $this->data = $data;
  9. }
  10. public function handel()
  11. {
  12. //业务处理区域
  13. echo 'success';
  14. }

控制器

  1. ues App/Job/TestQueue;
  2. public function queue()
  3. {
  4. $data = [
  5. 'name'=>'shangjin',
  6. ];
  7. TestRedis::dispatch($data)->onQueue('testRedis');
  8. }

消费

  1. php artisan queue:work redis --queue=testRedis

注意

  1. //Job内容修改后 需要重启 因为队列文件会进入缓存 导致修改后不生效
  2. php artisan queue:restart
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post